Answered by Shaykh Faraz Rabbani
Does praying with an erection invalidate the prayer, and is it better to wait until the erection dissipates before entering into the prayer?
Walaikum assalam wa rahmatullah,
There are only a limited number of things that invalidate wudu. Erection is not one of themthus, it would not affect the validity of your prayer.
However, deliberate thinking of anything outside the prayer is reprehensible and diminishes the spiritual value and impact of the prayer.
As for the things that invalidate wudu, see:
Is wudu invalidated by taking off one’s scarf?
Wassalam,
Faraz Rabbani