Fire doesn't just hurt the bad guys
My own players did this once. Well, twice actually, but these were implemented very differently. I'll go over both since they both illustrate different ways to handle (that is, limit) the use of fire.
Make fire endanger the party
My party came across a goblin encampment, and they decided that they needed to create a distraction so the rogue could more easily sneak in and scout the place. They couldn't set the encampment on fire, as it was actually underground. Instead, they decided to set the nearby forest on fire and start screaming about how all their valuables were going to be destroyed in the fire (no seriously!).
Between the ranger, who knew what all the most flammable types of wood were, and the sorcerer who took bonfire as a cantrip, they had absolutely no problem getting a blaze going. And oh did they! And with their dwarf shouting about all the gold he allegedly now had to carry, it was hardly any time at all before the goblins sent scouts and soldiers to check out the blaze and collect the goods.
Since they had time to prepare, they actually had a really good ambush set up and were at a solid advantage... except, the fire started spreading.
At the top of every battle round, I rolled a d8 for each separate flame (the party had set up two, and had created more by using Bonfire and throwing fiery chunks of wood). Each number corresponded to a direction, and that was the direction the flame would spread that turn.
Pretty soon, the party had to withdraw, because the spreading fire was actually close to cutting off their own escape. They even took some damage from it!
I didn't do anything real special here, and I don't have the fire spread and block them just because. But fire is dangerous, even to a party who has prepared really well! Using it is dangerous, and the more you use it the more chances you have to really mess up and get yourself hurt or killed. If you make sure your party is also in flammable surroundings, they just might think twice about using it so liberally. Mine certainly did.
Make fire endanger someone they don't want to hurt
Our rogue, meanwhile, was busy setting fire to a warg pen in the goblin camp (he had some really good stealth rolls). That worked wonderfully, but he was very careful to only target burnable structures where prisoners could not be held.
Why? The party was there specifically there to rescue an NPC who had gone missing, and my players did not want to accidently kill this NPC. This taught me real quick that collateral damage is a really good motivator not to use fire... if your PCs are concerned about such things.
This rogue was very careful in selecting his targets. His first question would be is it flammable, his second are there prisoners? He made sure the fire couldn't spread to anywhere that prisoners might be held, and when he couldn't do that, he just didn't use fire.
So, that's the second way to keep your party from freely using fire - put someone friendly in harm's way. I promise that if your party is thinking, and they don't want to hurt that NPC, then they probably won't ignite the building that person's being held in.
This can also work in a crowded city, where setting a villain's hideout on fire actually means setting the city itself on fire. Just be clear with your players that this is what will happen before they try.
Don't make the building flammable
Within city limits, my party didn't use fire very much at all. For one thing, they were actually trying to avoid collateral damage... but also they were in a city whose buildings were mostly made out of stone. Stone doesn't burn very well. And if the building won't burn, then there's no point trying to burn the bad guy's hideout down.
Any or all of these approaches should help. And if they don't, then you get some memorable stories out of it, and your party is probably wanted for arson and man-slaughter!