Under the Abbasids, enslaved people could gain their freedom if:
- They sued their masters for denying them slave rights
- They bought their freedom
- Their masters died - sometimes
- They gave birth for their masters
Enslaved people under Islam have certain rights and if the master does not grant these rights, the enslaved person can sue for their freedom.
Some enslaved people were also allowed to buy their freedom from their masters after some time and some were freed when their masters died.
hope this helps!