What defines which countries are permanent members
This is defined in section one of article 23 of the UN Charter, which says:
The Security Council shall consist of fifteen Members of the United Nations. The Republic of China, France, the Union of Soviet Socialist Republics, the United Kingdom of Great Britain and Northern Ireland, and the United States of America shall be permanent members of the Security Council. The General Assembly shall elect ten other Members of the United Nations to be non-permanent members of the Security Council, due regard being specially paid, in the first instance to the contribution of Members of the United Nations to the maintenance of international peace and security and to the other purposes of the Organization, and also to equitable geographical distribution.
So, for a country to become a permanent member of the UNSC, the UN charter would have to be changed. According to article 108 of the UN Charter, this requires
Amendments to the present Charter shall come into force for all Members of the United Nations when they have been adopted by a vote of two thirds of the members of the General Assembly and ratified in accordance with their respective constitutional processes by two thirds of the Members of the United Nations, including all the permanent members of the Security Council.
So, that is what is required to be a part of the UNSC.
All of my linked articles and quotes up till this point are from the official UN site.
Why Germany isn’t a permanent member:
This is partially explained in an answer by James K which says that stability is the basis of the security council, and adding more members undermines this. In addition, adding more members weakens the existing members.
The reason Germany wasn’t initially added to the UNSC was because positions on the UNSC were mainly awarded to the winners of WW2, and Germany lost. In addition, since the UN was created right after WW2, and Germany was not a country at that time