Cal. Penal Code Section 12027a is repealed (eff. Jan 1, 2010). The current Article related to retired law enforcement officers carrying a firearm is: Penal Code 25450-25475
The law is silent on whether or not the privilege to carry a concealed weapon preempts California Labor Code 2922, which provides that an employer can terminate any employee "at will:" at any time, for any reason, or for no reason at all.
It's not clear to me from your question as to whether or not your employer is public or private. If a public employer, then I suspect you may have a better claim, because the law clearly permits you to carry a weapon, and due process requirements imposed on public employers would prevent your immediate termination of employment without a hearing.
Private employers have no such restrictions, and Labor Code 2922 is generally enforced, unless there is preemption based upon unlawful discrimination (race, color, nationality, religion, sex, age, disability), jury duty, witness subpoena, military deployment, employer policy that requires a specific process prior to termination, report of employer criminal conduct to law enforcement, breach of collective bargaining agreement, etc.).
It could be argued that your termination 5 months before retirement as pretextual age discrimination. This could be especially true if your final retirement pension would be substantially enhanced if you were employed for the remaining 5 months before retirement.
Unfortunately, there is no specific case law on the direct issue of whether or not your 25450 (former 12027(a)) license to carry would operate to preempt Labor Code 2922. Consequently, the issue may be ripe for a lawsuit -- which could make the employer think twice about its decision. However, at this point, the age discrimination claim could be the better claim. If I were representing you, I would claim both actions, and see if anything "sticks" to the back of the courtroom wall.
Since you have a union, I would encourage you to utilize the grievance processs. If you can't get any traction, then you will need an employment rights attorney. Or, you can file a complaint directly with the Department of Fair Employment and Housing (DFEH), and let them investigate.
If you need a hyperlink to a lawyer referral service, or to the DFEH website, please let me know and I will be happy to provide.
Hope this helps.