Organizations often put new employees through shared trauma to force a feeling of comraderie and submission to management so I don't see why gangs would be any different.
Steven Hassan was a former member of the Moonies cult who obtained a PhD in psychology after being deprogrammed and has written books on the psychology of cult recruiting. Interestingly, he points out that the same tactics are often used by organizations that aren't cults. I highly recommend reading one of his books!
Remember that most gangs are made up of stupid as shit 12-18 year olds. Like really, gang members are young. These are preteens and teens with guns and weapons. They're fucking stupid.
How do you condition someone to be loyal/obedient and not a liability? You haze them with the implication that a whole lot worse could happen, and then you test them. "You gotta promise not to tell anyone this, I'm trusting you" usually loosely translates to "I just told you something bogus and everyone is listening to see if you're gonna spill the beans, and if so we'll beat the everliving shit out of you until you learn"
You either are jumped in and prove yourself to be tough enough to roll with them, or you can’t tough it out but they’ve already beat you to a pulp once so ideally they’ve made their point and intimidated you out of speaking against them/talking to cops or trying out for rivals.
Full disclosure: I don’t have experience in this and am mostly speculating.
You seen Fight Club? Making them stand on the porch while they were hit and berated was part of the initiation. It showed they were committed. Similar thoughts to gangs. Unsure how prevalent it still is.