In my state, building officials and their subordinates are indemnified by language in the code itself. The municipality, on the other hand, has to carry insurance or self-insure. I'm pretty certain most carry insurance.
Being indemnified does not mean you can't be sued. I've been sued -- in federal court -- along with my boss (the building official), the mayor, the zoning enforcement officer, and I think a couple of other municipal officials. The town's insurance paid for an attorney to defend us, and we got a good one. It was a bogus case anyway, and the result was that the case was thrown out when it finally reached a judge.
But we did get sued.