Assume person A owns an apartment and lets person B live there without a renting contract (so B's address is legally there). If now person A kicks B out, does B then have the right to a notice period (ordentliche Kündigung) or not? Would anything change if person A had a sudden reason for doing it such as a sudden diagnosis of a serious illness?
If person A lets person B live there, then there is a renting contract. It doesn't need to be on paper or in the standard form for there to be a renting contract.
Although it is not necessary, if person B is paying money to person A in order to stay in the apartment, this is even more solid proof that there is a contract, and makes it difficult for person A to lie something like "I didn't even know he was living in the apartment!"
In fact, absence of a written contract which would normally including a specific notice period, for example 4 weeks notice, gives even more power to person B.
If there were a written contract, I expect it would include a notice period, for example 4 weeks notice. There is no written contract, so there is no notice period. But this does not mean that person B should move immediately. It means that person A has no right to tell person B to move out within any specific period.
Without a written contract that includes a specified notice period, person A has much less rights to tell person B to leave. Probably, if person B wants to stay, they can stay for a very long time, as long as they keep paying the rent or whatever the original consideration was. Person A would need to go to a civil court or rental tribunal and show the reasons why person B should move out. This often happens, and in many cases it is ruled that person B does not have to move out.
Some common reasons in cases where it is ruled that person B should move out include: that Person A is selling the apartment, or that person A's previously separated spouse or child etc is coming back to live at the apartment and there is not enough rooms/facilities to accommodate an additional person.
So for your example, in most jurisdictions there would be no notice period, but this only means person B has more right to stay, and possibly for a very long time. At minimum, it would need to be decided at a court. If person A calls the police and tells them he wants person B to move out (which sometimes happens), police will tell person A to go to court because this is a civil matter and it is none of their business.