The episode with Stella's and Ted's (cancelled) wedding (Shelter Island, Season 4, Episode 5) where Barney (probably) has a threesome is after the episode about the belt (Third Wheel, Season 3, Episode 3) where Barney tells the story about his failed attempt at a threesome. So there are no mistakes in the timeline of the show.
There are a few misconceptions and assumptions in the question.
It's unproven that there was a second girl in the bedroom during Ted and Stella's wedding. I don't remember this implication, having watched the show multiple times.
Even if there was a third girl, the Bro Code stipulates limitations to "the tricycle". If any of these rules were violated, it ...