Praise be to Allah.
Firstly:
It is not permissible for you to take the salary in the two cases mentioned, so long as you did not get a leave of absence that would make it permissible for you to take the salary even though you did not do the work (sick leave, if you were actually ill, or maternity leave, if the system allows the pregnant woman to take a leave with pay).
Secondly:
In the first case, you should give in charity the salary that you got, or donate it to public facilities that the state usually spends on, and the closer it is to the field of your work (medicine and hospitals), the better, because there was no one who took your place at work and you cannot give the money back to the state.
In the second case, it also seems that you should give it in charity, because the one who did your work in your stead did not do it in an official capacity with permission from the one who is entitled to give permission for that, and the employment system does not allow an employee to appoint someone else to act in his stead, with or without a salary.
For more information, please see the answer to question no. 105403
For information on things that prevent supplication (du‘aa’) being answered, please see the answers to questions no. 13506 and 5113
And Allah knows best.
Comment