I know that punishing oneself and depriving oneself is effective in encouraging oneself to do good, but how can I punish myself?
Punishment comes after learning the truth and deviating from it. You should not start with punishment because there is no punishment before knowledge and knowledge leaves no excuse.
You should also note – may Allaah bless you – that punishment should not be sought as an end in and of itself, rather it is a means of disciplining the self. This is like cauterization for one who is sick, which is only used as much as is necessary.
It is not good to punish yourself and burden yourself with more than you can bear, or with things that cause physical harm, such as burning yourself with fire or standing in the sun, etc. Rather punishment should take the form of obliging yourself to do more righteous deeds, without causing too much hardship, or depriving yourself of things that you like. However, you know yourself best and you know what makes you more lazy and pushes you towards sin, and you should avoid these things.
Al-Maqdisi (may Allaah have mercy on him) said:
If the believer checks himself and sees some shortcoming or he commits some sin, he should not take the matter lightly, for that may lead to him committing sin regularly and then it will be difficult for him to give up that sin. Rather he should punish himself in a permissible manner just as he would discipline his wife and children. It was narrated that ‘Umar went out to a garden he owned, then he came back and the people had prayed ‘Asr, so he said, “I went out to my garden and when I came back the people had prayed ‘Asr; I give my garden in charity for the poor.”
And it was narrated that Tameem al-Daari (may Allaah be pleased with him) slept one night and did not get up to pray Tahajjud (late night prayer)until dawn came, so he prayed qiyaam al-layl (voluntary night prayers) for a year and did not sleep in order to punish himself for sleeping that night.
Hassaan ibn Sinaan passed by a room and said, “When was this built?” Then he thought to himself and said, “Are you asking about something that is not your concern? I will punish myself by fasting for a year,” and he fasted that year.
But with regard to punishments that cause physical harm or involve doing something reprehensible, they are not permissible. It was narrated that a man looked at a woman, then he put his eyes out, and that another disobeyed Allaah with his hand, so he put his hand into the fire until it became paralyzed. Such actions are not permissible, and a man cannot treat himself in this way.
From Mukhtasar Manhaaj al-Qaasideen.
And Allaah knows best.