The Church considers suicide to be gravely wrong. The sacrament of confession is part of the Last Rites, the priest cannot absolve someone who is about to freely choose to do something that is gravely wrong. For the Church to anoint someone in these circumstances would give the appearance of approval of their actions.
Individuals in such situations are not evil or bad people, they are struggling with the very difficult realities they are facing. The refusal of the sacrament is not meant to be a punishment but rather is meant to underscore the gravity of the action and awaken the conscience of the individual to its wrongness.