California's rule is that California military servicemembers who leave California under PCS orders become nonresidents of California for income tax purposes. California taxes non-residents only on California-source income.
https://www.ftb.ca.gov/forms/2023/2023-1032-publication.pdf
The gain or loss from the sale of stocks or bonds has a source where you are a resident at the time of the sale. Since you were considered a non-resident of CA at the time you sold your stocks, the capital gain is not California-sourced and therefore not taxable by CA.
**Answers are correct to the best of my ability but do not constitute tax or legal advice.