Because it carries verbal-noun meaning, a Masdar Muawwal can occupy a noun’s place in a sentence.
● أَنْ تَصُومُوا is the topic (mubtada) in أَنْ تَصُومُوا خَيْرٌ لَكُمْ.
● أَنْ أَخْرُجَ is what is wanted in أُرِيدُ أَنْ أَخْرُجَ, so it functions as the object of أُرِيدُ.
A Masdar Muawwal may also serve as khabar, subject, and other noun roles. Those roles are not guessed from the phrase alone; the whole sentence determines the role.