Why does it happen that when I make an intention to go to the mosque I get a lot of distracting thoughts that lead me to eventually abandon my intention?
as salam alaikum
intentions should be followed by actions. If actions do not follow intentions on a regular basis, it may indicate that the intentions have been not formulated fairly. In fact intentions are the cause and deeds are the effect. A famous prophetic hadith says: "Truly the deeds are only according to the intention and to every man is that which he has intended". It is the intention that defines the action; working on the intention therefore should bring a better and/or more refined action insh'Allah.
You may also make a list of priorities and put the salat in the masjid at the top of your list, then keep vigil and focus on what is most important with Allah's assistance.
With prayers for your success.