Since we only have bones, we can’t say for sure, but what if the chambers for example in the skull of the Parasaurolophus dinosaur for example were like the chemical mixing chamber of the modern Bombardier beetle, which can send repetitive bursts of boiling hot liquid into the face of its foes.
See more about the Bombardier Beetle here: https://www.youtube.com/watch?v=TgqF-ND2XcY