Deposit rules don’t change
Yes. Your security deposit rights generally apply regardless of whether the unit was legally permitted. A landlord cannot keep your deposit just by claiming the unit was illegal.
Under California's security deposit rules, after you move out the landlord must return your deposit, minus only lawful deductions such as unpaid rent or repairs for damage beyond normal wear and tear, and must provide an itemized statement within the required time. These rules do not disappear because the unit was unpermitted.
In fact, if you were pushed out of an illegal unit through no fault of your own, or the unit had serious defects, that context may strengthen your position on getting your full deposit back.
Keep records — your lease, proof of what you paid, photos of the unit's condition when you moved in and out, and any written communications. If a landlord refuses to return your deposit or makes improper deductions and points to the unit being "illegal" as the reason, that is generally not a valid excuse. A free, confidential review can explain your deposit rights and options.
This is general information about California tenant rights, not legal advice. Every situation is different.