Even though all kinds of sinful thoughts may pass through our brains, it is our Christian duty not to entertain them because sinful thoughts soon become sinful deeds. When you recognize a sinful thought against God, you must immediately ask for His forgiveness and then ask Him to help you let go of every thought that is not in harmony with His character and His word. By sincerely laying your sin before Him and asking Him to give you strength where you are weak, He will uplift you and support you.
You asked why you think immoral things against God. You think these things because you are an imperfect human being, as we all are. Our imperfect fleshly mind is warring with our spiritual mind. Staying spiritually minded is difficult and not a job that we are capable of doing alone. We need God’s help. The Apostle Peter tells us to humble ourselves under God’s mighty hand and cast our cares and anxiety on him so that we will be lifted up in due time (1 Peter 5:6-7).
Peter further admonishes and encourages us. “Be self-controlled and alert. Your enemy the devil prowls around like a roaring lion looking for someone to devour. Resist him, standing firm in the faith, because you know that your brothers throughout the world are undergoing the same kind of sufferings. And the God of all grace, who called you to his eternal glory in Christ, after you have suffered a little while, will himself restore you and make your strong, firm and steadfast.” (1 Peter 5:8-10) How encouraged we are by these words! God is merciful and will restore us and make us strong, firm and steadfast.
Continue to fight the good fight, relying on God’s strength to support you. All of us are struggling Christians and are subject to temporary setbacks. As long as your heart is pure and you sincerely want to put down your old nature, God will forgive your shortcomings and assist you on your Christian walk. Stay focused on the Apostle Paul’s words, “Whatever is true, whatever is noble, whatever is right, whatever is pure, whatever is lovely, whatever is admirable—if anything is excellent or praiseworthy—think about such things.” (Philippians 4:8)
By looking to God for strength and not relying on your own perceived strength, you will be able to overcome all obstacles, even your own flesh! “Let us then approach the throne of grace with confidence, so that we may receive mercy and find grace to help us in time of need.” (Hebrews 4:16)