Dementors are intelligent creatures. [TheirTheir condition as guards of Azkaban was negotiated long ago]ago. From the fandom wiki:
When Damocles Rowle was elected Minister for Magic in 1718, he insisted on utilising Azkaban's dark pedigree, seeing the Dementors as a potential asset: putting them to work as guards would save expense, time, and lives. This plan was eventually put into motion and, despite protests, Azkaban remained the prison of the wizarding world right up until the Second Wizarding War, mostly because of its near-zero breakout rate. From that point on, the Dementors served the Ministry of Magic as the guards of Azkaban, as the arrangement allowed them to feed on the emotions of the prisoners within its walls.
They were basically government employees:
Though their primary function was to guard Azkaban, Dementors also performs [sic] other services for the Ministry, such as being sent to guard other locations, escort prisoners to trial or even hunt down certain criminals.
Since the dark wizards held the Ministry of Magic, they also held the dementors' meal ticket. Not that the dementors needed the Ministry, but you know... Everyday I am given the option to either toil at my job in exchange for a salary, or to say eff it all and start hunting my own food. Everyday I choose the former. I think dementors like being sedentary just like me.