Peace be upon you,
Regarding your inquiry about intrusive thoughts related to purity and how to overcome them, we recommend reviewing the following question:
We have elaborated on the answer there.
As for your specific issue, consider the following points:
1- The origin of sexual thoughts, even if they arise during prayer, reflects a physical state related to sexual energy. If these thoughts lead to the release of fluid, it indicates a need to address your dietary habits, as certain foods (like fish, avocado, honey, cream) can enhance sexual energy.
2- It has been reported in various narrations that fasting helps control sexual energy. Therefore, committing to fasting on certain days can positively impact your situation.
3- Distractedness in prayer, regardless of the nature of the thoughts, can be addressed by controlling the imagination. We recommend studying scholarly works on the etiquette of prayer, such as Imam Khomeini's "Spiritual Etiquettes of Prayer" and "Secrets of Prayer" by Maleki Tabrizi, among other beneficial texts. Understanding God's greatness during the opening Takbir and entering prayer is crucial in preventing distraction, as it fosters a deep connection with the Divine. Strengthening your spiritual relationship with God outside of prayer significantly influences your situation.
4- Satisfying your sexual urges through permissible means can help relieve your body of excess fluids, thereby reducing the triggers of these thoughts.
5- Regarding the jurisprudential aspect of your question: Ayatollahs Khamenei and Sistani state that these fluids are considered pure unless they are urine, semen, or blood. Therefore, there is no need to interrupt your prayer or perform ablution again.
May you be successful in all good.
Source: