The function of hell is to punish sinful souls who committed a lot of sins in their human form of life. For example, the sin of killing a cow is so bad that you cannot accept the complete karmic reaction in this life on planet Earth. That's why hell exists for this purpose, so that one accepts the karmic reactions.
Garuda Purana says that those who turn away from devotion to the Supreme and become sinful, inevitably go to hell.
8-9. Once, when the Blessed Hari, the Teacher, was sitting at ease in
Vaikuṇṭḥa, the son of Vinatā, having bowed reverently, inquired:--
Garuḍa said: The Path of Devotion, of many forms, has been described to me by you, and also, O Shining One, has been told the highest goal of the devotees.
Now I wish to hear about the fearsome Way of Yama, along which is the travelling, it is revealed, of those who turn away from devotion
to Thee.
The name of the Lord is easily pronounced, and the tongue is under control. Fie, fie upon the wretched men who nevertheless go to hell!
Tell me, then, O Lord, to what condition the sinful come, and in what way they obtain the miseries of the Way of Yama.
The Blessed Lord said: Listen, O Lord of Birds, and I will describe the Way of Yama, terrible even to hear about, by which those who are sinful go in hell.
14-16. O Tārkṣya, those who delight in sin, destitute of compassion
and righteousness, attached to the wicked, averse from the true
scriptures and the company of the good,
Self-satisfied, unbending, intoxicated with the pride of wealth,
having the ungodly qualities, lacking the divine attributes,
Bewildered by many thoughts, enveloped in the net of delusion,
revelling in the enjoyments of the desire-nature,--fall into a foul
hell.
- Those men who are intent upon wisdom go to the highest goal; the sinfully-inclined go miserably to the torments of Yama.