Hi and welcome to the forum
A 5 gallon tank is too small for general aquarium fish and whilst a male Betta can live in it, there is insufficient room to safely house other fishes with him. In addition to this, having 2 male Bettas next to each other where they can see each other all the time, is stressful to the fish. Male Bettas have territories about 2 feet in diameter. When another male comes into his territory they fight and one usually swims away, or one gets killed. After the fight there is time (days or even weeks) before another male will come into the territory and another fight occurs.
If you have 2 male Bettas in tanks next to each other and they can see each other, there will be constant stress with each male trying to drive the other out of its territory. This constant stress produces hormones that will shorten the fish's lifespan.
If you want 2 male Bettas, keep them in separate tanks next to each other and have a piece of black card between the 2 tanks so the fish can't see each other. Then several times a week you can remove the card and allow the fish to see one another. They will show off and try to kill each other but won't be able to do any physical harm. After 15 minutes or so you put the card back between the 2 tanks and leave it there for a few more days to a week. Each male will think it has driven the other male away and strut around the tank feeling like a big man.
This way of keeping Bettas allows them to display and fight over a territory once or twice a week and be rested and relaxed for the rest of the time.
If you want a community tank, get a tank that is 3 foot long and keep community fishes in that and keep the Betta in the 10 gallon with a few shrimp and maybe a mystery/ apple snail
