Assalamualaikum, I actually wanted to know that is a sin only counted when a person does that sinful action or speaks about it or you can still be accountable for what happens in your mind? I rade a hadith which said you are not accountable for whatever crosses your mind so does this mean even if a person intentionally thinks of a sin in his mind but doesn't do it, will it still be not counted as a sin?
Yes it is true as mentioned in this hadith:
It was narrated from Abu Huraira that the messenger of Allah Subhan Tallah Said:
"Allah, the Mighty and sublime said: If my slave thinks of doing a good deed and does not do it, I will write it down as one good deed. If he, does it, I will write down for him between ten and seven-hundred fold. If he thinks of doing a bad deed and does not do it, I will not write it down, and if he does it, I will write it down as one bad deed." (Sahih Muslim, the book of faith: 335)
Because Allah Subhan Tallah knows that as mentioned in a hadith:
"Satan circulate in the human mind as blood circulates in it, and I was afraid that Satan might throw an evil thought (or something) into your hearts." (Sahih Al Bukhari: 3281)
Anas narrated that the Prophet PBUH said:
"Every son of Adam sins, and the best of the sinners are the repentant." (Tirmidhi:2499)
Just imagine for a moment what happened if our all evil thoughts appear before all of us. but its Allah's blessing that He has put them in a veil and also don't account for them but still remember one thing that we should seek refuge in Allah Subhan Tallah from such thoughts as they can become actions if not tackle properly.
However, there are lots of prayers like Prophet Muhammad pbuh used to make dua to seek refuge in Allah from Satan, he used this prayer in salah and blow towards the heart, three times:
أَعُوذُ بِاللَّهِ السَّمِيعِ الْعَلِيمِ مِنَ الشَّيْطَانِ الرَّجِيمِ مِنْ هَمْزِهِ، وَنَفْخِهِ، وَنَفْثِهِ
"I seek refuge in Allah from the accursed devil, from his puffing up (nafkh), his spitting (nafth) and his evil suggestion (hamz)."(Sahih Al-Kalim Al-Tayeb No# 130)