I'll go straight to the MWE:
\documentclass{article}
\newcommand\mymacro{\MakeUppercase{this is my macro}}
\begin{document}
Foo \mymacro bar.
\end{document}
In my understanding, this should produce Foo THIS IS MY MACRO bar., but instead I get Foo THIS IS MY MACRObar., using both xelatex and pdflatex.
What is wrong with the macro above?

\mymacro baror\mymacro barTeX will printTHIS IS MY MACRObar. This is because if it didn't ignore spaces, it wouldn't know that what\mymacrobaris. If you want spaces after control sequences you can use\mymacro\ baror\mymacro{} baror usexspaceas Bernard suggested... – Phelype Oleinik Sep 14 '18 at 23:13