Answer
If you leave early, you may lose the deposit: in the example of departure before an annual contract ends, it is not returned and insurance covers the losses. It is also indicated that when leaving 6 months before the end of the contract, the deposit may not be returned.
This is not a universal automatic rule for every apartment. The consequences depend on the contract, rental guarantee, and agreement between the parties: sometimes the tenant is responsible for the remaining term or until a replacement tenant approved by the landlord is found.
Before signing, clarify separately the minimum tenancy period, notice requirements, penalties, the option to find a replacement tenant, and the procedure for returning the deposit. You cannot simply treat the deposit as payment for the final month and consider your obligations discharged.