To the best of my knowledge in the Federal Government, the firearm belongs to the tax payers. You are not allowed to take your firearm home with you if you should retire from any of the military services. The only exception I know of is General Officers, and they have to buy it (General officers have an option to purchase their holster and pistol at retirement at a price well below market value. As per: Senior Leaders Handbook for General Officers)
It sounds as if various state and local governments have their own rules.