Place the yucca in the sunniest location in your home. Yucca plants are desert plants, and placing them in the sun will help the soil to dry out.
Withhold water from the yucca plant. Allow the soil to dry out for several days. When you do water again, only provide enough water to moisten the soil. Repeat this step to eliminate fungus gnats.
Mix a natural bacillus toxin into the water that is safe for plants, but kill the gnat larvae. Repeat applications may be needed to treat the yucca plant. Read and follow label directions.
Insert sticky stakes by the yucca plant. The gnats become stuck on these stakes. When the stakes become full, toss them away into the trash for the garbage collector to haul away.
Remove the yucca plant from the pot is possible. Wash off all the old soil. Repot the yucca into new soil. Take the old soil and sterilize it or leave it to dry in the hot sun.