this is my personal opinion, (I’m not a doctor, so I can not say anything about mental health or whatever) When I was younger, thoughts like this came into my head from time to time. I was going through a dark period in my life. What I will say and again this is MY OPINION is that those thoughts were a result of a spiritual battle going on in my life. In my experience going to Confession and dumping everything that is on your mind no matter how horrible, praying the rosary daily, and understanding that you literally cannot sell your soul helped me with these thoughts.
God loves you and wants you into heaven with him MORE THAN YOU DO haha! Trust and love him. Read his written word and always say prayer when these “spiritual battles” come around (I say something like, Lord Jesus, help me…Mary Mother of God, crush the head of these evil thoughts, etc.) You also have a guardian angel who has been with you since birth. He also would like to help you, so ask for his help.
As others have stated, blasphemy against the Holy Spirit is final impenitence. Going to confession and trusting that God has forgiven you usually helps me with this. Also, a sin is not mortal if you do not will it.