It's usually possible to change substrate with fish in the tank, not advisable if the substrate has been in there for more than a year or so though, or is prone to gas pockets - potentially lethal if a gas pocket gets disturbed while there are fish in there.
With
soil? I wouldn't even attempt it. That's guaranteed to be messy. You don't need a whole other tank to move them to, you can set up a temporary one using a food grade plastic storage tote, like this one
Get a heater guard for your heater if it doesn't have one, then when you're ready, move the filter/heater/airstone etc to the tote/tank, with most of the tank water, then the fish and any live plants, decor etc. Make sure to cover the top with something to prevent jumpers. Then they can stay in the tote while you take your time removing all the soil from the tank.
It would be a struggle to remove every bit of soil from the tank while the fish were in there, even if you left aside risks to fish from gas pockets, and how messy it would get.
Remember that a lot of your beneficial bacteria population would have been living on the substrate too, when you change it, so there's every chance the tank will go through a mini cycle. That's not a problem as long as you're aware of that so you can test and water change as needed!