Why are there tiny flies in my houseplant soil?
They are almost certainly fungus gnats, and they are a symptom rather than the problem. Fungus gnats breed in permanently damp compost, so their presence is telling you the pot is staying wetter than it should.
Adult fungus gnats are small dark flies, a few millimetres long, that drift up when you disturb a pot or water it. The adults are harmless and short-lived. The larvae live in the top few centimetres of compost, feeding mainly on fungi and decaying organic matter. In large numbers they will also graze fine root hairs, which is enough to weaken seedlings and cuttings, though established plants generally tolerate them.
The life cycle is the key to controlling them. Eggs hatch within a few days and the whole cycle completes in around three to four weeks, so any treatment needs to keep running for at least a month to break it. Killing the adults you can see does essentially nothing on its own.
The effective approach is to make the top layer of compost inhospitable. Let the surface dry out properly between waterings — most houseplants tolerate this far better than people expect. Water from below, so the surface stays dry while the roots drink. Cover the compost with a centimetre or two of horticultural grit, which the adults cannot lay through and the larvae cannot cross.
Yellow sticky traps are useful for monitoring and for catching egg-laying adults, but should not be your only measure. For a stubborn infestation, a biological drench containing predatory nematodes or the bacterium Bacillus thuringiensis israelensis targets the larvae directly.
Also check whether the pot has working drainage and is not standing in a full saucer.