So to take things in sequence, beginning with How's...
The world of explosive compounds goes way beyond gunpowder, although there is a small amount of charm there. Sulfur, Saltpetre, and Carbon in a diet seems like it would be simple to arrange, but it seems a bit limited to me. Fuel to air mix with any number of flammable gasses will also create a satisfying boom. A lot of these natural gasses are also pretty easy to arrange.
Almost all vertebrates have some beneficent bacteria in our intestines. These help us digest a broad variety of foods. The bacteria break down certain parts of the food and produce a variety of gasses. One of the more common gasses is Methane. Normally the gas is passed on through, resulting in humorous noises and sometimes clearing rooms.
Depending on your creature, this can have a variety of benefits. Methane is lighter than air. It can also be ignited with palladium.
So give the critter a reason to float or fly and have him live in an area rich in palladium. As the critter grinds up palladium rich rock or gathers it in something like a bird craw, it can expel it through that and you get jets of flame. Alternately it may try to float away. Your reasons can vary pretty widely.
(Edit: I forgot the Why's)
Flame for defense seem to be a pretty good solution. For Nest defense. It actually plays both ways. A good flame digestion cycle as a re-usable tool to set bad critters on fire would work pretty well. Adult animals are known to sacrifice themselves for their young. That's where an explosion could work. Last ditch effort to drive away multiple nest raiders, or maybe a really big one. The little critters would have to still be in eggs or protected in some way from the blast.
Put the creature in a hardened external shell and you could have Shrapnel to go along with the concussion. Also, with the shell, you could have a different version of Bobby the Boom Turtle.
Have fun with your demolition pets!