Magic accesses demiplanes all the time. So there's no reason not to think that magic that brings matter or energy into existence comes from alternate dimensional places and planes. So if the Conservation of Mass and Energy is a scientific thing you actually care about for the physics of your campaign world... shunting or accruing energy and matter from other dimensions via magic is the way to go.
You don't even need to imagine it. It's RAW.
The worlds with in the D&D multiverse are magical places.
All existence is suffused with magical power, and
potential energy lies untapped in every rock, stream, and living creature, and even in the air itself. Raw magic is the stuff of creation, the mute and mindless will of existence, permeating every bit of matter and
present in every manifestation of energy throughout the multiverse."
And...
"Whenever a magic effect is created, the threads of the Weave intertwine, twist, and fold to make the effect possible."
So the magical energy is there, you access it through the Weave which uses that energy to manifest the effect.