thank you for sharing your question with the Wefugee Community!
Since I dont have much information about your case I can only give you some general information. If the mother and the child hold a residence permit it is in general possible for the father to also get one. But it is not always easy and depends on the circumstances in your case.
Since the father of your child doesn´t stay in Germany legally that complicates the situation of course. It is a criminal offence to stay illegally in Germany. Therefore I would recommend you to see a lawyer and talk to him/her about your case. If you can´t afford one, you can find a free and trustworthy counselling centre via this website. They can give you more information about your question and maybe even recommend a good lawyer to you:
I hope this answer was helpful. Please don´t hesitate reaching out to the Wefugees Community if you have further questions!
All the best
Note: Please keep in mind that we can´t provide qualified legal advice via the internet and that any information given can´t replace such legal advice.