In the wild it's not a problem--males establish and defend territories, and females swim freely among them, so they don't stay together. Most wild bettas are also not as aggressive as their domestic counterparts.
For domestic bettas, the process is more complicated. A breeder first has to condition the chosen pair with rich, meaty food like bloodworms for about 2 weeks. The male is then placed into a separate breeding tank, where he'll build his bubblenest--a cluster of bubbles on the surface that he blows by mixing water with mucus. Then the female is added to the tank in a separate container, so that she and the male can see each other but can't get at each other. The male will start flaring and displaying at her, and, if she's ready to spawn, she'll get a pattern of dark, vertical bars along her body.
The breeder will keep the female in this container for at least several hours before releasing the female into the tank. After she's released, if all goes well, the male will begin chasing her and trying to entice her to follow him under the bubblenest. Once there, the male will wrap his body around the female and squeeze, causing her to release her eggs, which he fertilizes. This causes the female to go briefly into a trance-like state. While she's immobilized, the male collects the eggs in his mouth and spits them into the nest. This process is repeated until the female is finished laying eggs.
Once the spawning is over, the female is immediately removed back to her own tank, since she has no further role to play and would be attacked by the male as he defends the nest. The male watches and guards the nest until the eggs hatch. Once the babies start emerging, the male will chase down any that fall from the nest and carefully put them back in. This can get a little hectic, since a single spawn can produce hundreds of fry! Once the babies are free-swimming (able to swim on their own), however, the male's job is done and he's put back in his own tank to rest and recuperate.
So that's basically how betta breeding works. Of course, it doesn't always go so smoothly--sometimes the male or female will be too aggressive to spawn, or they won't be conditioned properly, and the breeding just won't work.