What is the purpose of declensions? I know that 1st declension is female second is male and 3rd is neuter, but then why 4 and 5? What is the purpose of several declensions?
The relation between genders and declensions is more complicated than you list. The first declension contains mostly feminines, but there are also feminine-looking masculines like nauta and some masculine-looking Greek male names like Aeneas and Anchises. The second declension contains mostly masculines and neuters, but also some masculine-looking feminines. The third declension has all genders. The fourth one has mainly masculines, but also a couple of neuters like cornu and masculine-looking feminines like quercus. Perhaps the purest declension in this respect is the fifth one, which has almost exclusively feminines, with the exception of the genderfluid word dies.
But this only makes your question ever more important: Why make it so complicated?
Languages are not rationally designed and optimized. They evolve when used by a community. Things like this don't have anything I would call purpose, but we can still understand how they came to be.
The morphology of nouns was quite complicated already in Proto-Indo-European. Latin inherited this structure and it evolved in Latin and its predecessors. In fact, Latin was quite good at regularizing inflection, dividing words into a small number of categories with clear endings for each form. You can find a good description of the origin of Latin's five-declension system in this older question.
It should be noted that Romance languages derive from Latin, but they have lost much of the complications with nouns in Latin, dropping many forms and declensions. This suggests that those peoples and perhaps already the speakers of vulgar Latin in antiquity agreed with you and saw that they can make do with less.