Most firearms should work in a burning building. There may be some edge case that won’t, but I can’t think of any off hand. That said, any firearm with an exposed powder pan (like a flintlock, wheellock, or matchlock) could easily discharge on its own, if a spark ignited the exposed powder. They’d still work, it just might be much sooner than you were planning.
I’m not sure about percussion cap guns, but they might have a similar issue. These had a nasty habit of chain firing, where the spark from one cap would ignite another, firing multiple rounds at once. This wasn’t a serious problem with pepperbox pistols, instead of one round, it would fire two or more. But it could be a serious issue with revolvers and turrets, where the extra rounds could strike the pistol or (in the case of turrets) the operator. I don’t know if flecks of fire hitting the caps will ignite them, but it is a real risk.
Bullets will discharge if sufficiently heated, called “cooking off.” For example, being tossed into an open flame or into a heated skillet will result in rounds igniting. (Don’t do this, seriously.)
Cooking off can also occur with a firearm that is substantially overheated. If the chamber is too hot, the firearm will cycle, the round will cook off, causing the firearm to cycle again. This is called a “runaway gun.” At this point the only solution is to keep it pointed down range until it runs dry.
It’s probably worth pointing out: Automatic firearms generate a lot of heat, and dealing with that is an important engineering consideration in designing them. Guns that will runaway after extended use are a real issue.
Taking a firearm into a burning building is, in general, a bad idea; much like going into a burning building.
Now, if the gun or ammunition is engulfed in flames, that’s a different problem. As I mentioned earlier, actually setting ammunition on fire will result in it discharging on its own. This is more likely to involve the rounds detonating in the magazine and shredding it, than the gun firing uncontrollably.
This is more of an issue if you’re talking about an ammo cache in the burning building, rather than something your characters took in. If your characters are carrying their firearms, they shouldn’t have any particular issues. At least, none that affect the guns before the smoke and fire finished off anyone left alive.
That said, ammunition left behind in a building would be a serious consideration for fire crews trying to deal with the blaze.