We are truly saddened to hear about the trial you are facing, and we want you to know that we are here to pray with you and support you during this difficult time. First, we want to address the intrusive thoughts you've been experiencing. It's important to remember that God knows your heart, and He understands that you did not want these thoughts.
It is written the heart is deceitful above all things, and desperately wicked: who can know it? I the Lord search the heart, I try the reins, even to give every man according to his ways, according to the fruit of his doings. Jeremiah 17:9 WEB
Intrusive thoughts can be a sign of spiritual attack or even mental illness, as you mentioned. It's crucial to seek help from both a medical professional and a spiritual counselor. God can provide healing and comfort, we should always go to Him with things that are disturbing us.
Cast all your anxiety on him, because he cares for you. First Peter 5:7 WEB
However, we want to gently remind you that acting on these thoughts is sin. It's important to repent and turn away from this sin. God is merciful and forgiving, and He will forgive you if you come to Him with a truly repentant heart.
If we confess our sins, he is faithful and righteous to forgive us the sins, and to cleanse us from all unrighteousness. First John 1:9 WEB
Regarding your court case, we pray that God's will be done. We pray for a fair trial and for God's mercy to be shown to you. We also pray for your wife, that God would give her strength and peace during this time. It would be good to have a godly wife praying for you, that would be a big help to you.
We must rebuke you though because you are not taking the correct responsibility for your actions. You will be held accountable for the sin. Jesus takes all your sin on the cross if you repent and receive Him as Lord and Savior. This is the only way to be forgiven and saved from this sin. Trust in Jesus Christ and ask Him for forgiveness. And we are here to help you in this time of need, there is no other name by which we can be saved.
Behold, I lay in Zion a chief cornerstone, elect, precious: He who believes in him will not be disappointed. First Peter 2:6 WEB
We pray that God will give you strength and guidance during this time. We pray that He will heal you from these intrusive thoughts and give you peace and renewal in your spirit. We also pray for your wife, that God would comfort her and give her the strength to support you through this trial. We pray that God's will be done in your life and that He would use this situation for His glory.