It's not that much of a mystery. What you're seeing is a vacuum reservoir for various accessories that require a constant source of engine vacuum, depending on your year and model. For any year and model, it connects to the heater controls. I don't know about later models, but on older ones it powers the cruise control, and on models with a vacuum axle disconnect it powers that. If it leaks or breaks, your heater will default to defrost and your axle may pop out of 4WD. If you bypass it, everything will work but will go off when engine vacuum goes low, for example, as you crest a steep hill.
Pre-87 XJ's have metal ones in the engine compartment. After 86, depending on year and model, it might be a little globe, or an elongated "blimp." My 87 had a double-chambered blimp, with one side for the heater and axle disco, the other for cruise. Whatever type you have, it will also have a check valve built into each inlet.
And yes, you can relocate it into the engine compartment. In pre-91's it nestles pretty well under the radiator bottle. Aside from making it less vulnerable, it also takes the vacuum lines on a different route. A common cause of vacuum problems is in the plastic lines that go beneath the battery, which get eaten up by the acid.