All perfect praise be to Allaah, The Lord of the worlds. I testify that there is none worthy of worship except Allaah and that Muhammad is His slave and Messenger.
If it is possible to combine between the two matters, then this is better, otherwise preoccupation with acquiring Islamic knowledge is better in general, Allaah says (what means): {Say: Are those who know equal to those who do not know?} [Quran 39:9]
Allaah also says (what means): {Allaah will raise those who have believed among you and those who were given knowledge, by degrees. And Allaah is Acquainted with what you do.} [Quran 58:11]
But there may be some circumstances that make endeavoring to free the oppressed prisoners better in regard to a specific person. Rather, the matter may become an obligation on him, as is the case of communal obligations that become an individual obligation on some people.
Ibn Battaal said, “Supporting the oppressed is a communal obligation on the believers; if some do it, then its obligation is removed from the rest. This obligation falls first of all on the Muslim ruler and then on whomever is able to support the oppressed if there is no one else to support him such as the Muslim ruler and the like.”
Allaah knows best.