Anyone who is leaving Germany and moving to another country is legally required to deregister. (German term for deregistration) should ideally be done before your departure as it is less complicated for you to do it in person than via mail (why will be explained later in this article).
As part of the social security act, Germany has a mandatory state pension. Contributions into the German state pension are compulsory for all employees. This means that a certain percentage of your net salary (9,3%) is going towards the state pension. Hence, if you have worked in Germany for some time, there is a big possibility that you paid a lot of money into your pension without even knowing it. If you moved away from Germany, you might be eligible to claim your pension contribution without waiting until you turn 65.