Actually, I just realized that changing those 2 lines to:

#+LaTeX_HEADER: \BeforeBeginEnvironment{minted}{\begin{mdframed}}
#+LaTeX_HEADER: \AfterEndEnvironment{minted}{\end{mdframed}}

in the SETUPFILE works too. I don't recall the reason why I did not have them as LaTeX_HEADER earlier.

But the question still remains.. is SETUPFILE designed to not export lines beginning with #+LaTeX? Or a general question would be.. what stuff doesn't SETUPFILE export?