According to the German Postal Act (Postgesetz), anyone who intentionally opens, delays, or destroys a postal item without authorization can be punished with a fine or imprisonment of up to one year. This includes mail that is addressed to someone else, as well as mail that has been delivered but not yet opened by the recipient.
There are a few exceptions to this rule, however. For example, it is not illegal to open mail that is accidentally delivered to your address, as long as you return it to the sender as soon as possible. It is also not illegal to open mail that is addressed to you, but has been sent to the wrong address.
In general, it is best to err on the side of caution and avoid going through mail that is not addressed to you. If you are unsure whether it is legal to open a particular piece of mail, you can contact the German Postal Service (Deutsche Post) for more information.