Have seen this go wrong so many times. Here's may take:

1. As many people have mentioned, pay. Don't invent "noble" excuses, e.g. 'you must want to be here because we innovate so much' to avoid a pay discussion - those things work, but to a point. Pay matters. You don't have to pay the highest in the market, although that obviously works. But it has to be competitive, and hikes/increments should be regular to reward good work. This also has to be proactive: if someone has already begun to look outside, its probably too late for retention.

2. Peers. Smart people hang with smart people. If you staff team A with qualified folks, but team B has people not as qualified to the point that collaboration exercises are frustrating, either people from team A leave (they feel team B gets nothing done) or from team B leave (because they feel they're being lorded over, or feel team A is working on abstract pointless things).

In general, impedance mismatch at the level of skills or intellect is something to be wary of.

3. Bad apples. During hiring you need someone with fresh perspectives, but still aligned with the culture at some deep level. Its a bit like the superficial adage we hear about in dating: "opposites attract" - except they don't when you start living together. You are on your way to build a meritocracy, and then accidentally hire this person who wants to "play the game" to rise up the ranks, ruining it for everyone. Competent, hard working people don't want to spend time playing politics, and at some point they're going to reach out to their network to look for better teams.

4. Be transparent. You don't have the budget to hire the top talent in all depts? Be honest about it. Don't give out vibes like "we hired X anyway because we think he's good irrespective of what the interview panel felt" - people would eventually figure out that you don't think X is that great either, esp over candidate Y who got top scores from the panel but you glossed over, and you're just hiding budget decisions. Welcome, erosion of trust begins here.

5. Don't micromanage and stay away from pushing biased agenda down the chute. I think these are fairly well known. If you hire people qualified to do a certain job, let them do that job. Don't prescribe minutiae because you found them hyped up in a blog post. If you want a discussion, set up brainstorming sessions where you make it clear that you're probably going to come in with silly ideas to discuss.

One of the best managers I have worked with knew very little about my area, but one-on-ones were a delight with him because he would have many questions/thoughts about the project from the perspective of an inquisitive layperson. It made me want to improve.

6. Small acts of trust. Instead of conveying what you learned from speaking to a customer to distilling it to "code features X, Y, Z", expand the involvement of your team by actually talking about the discussion you've had. Invite perspectives and suggestions. It tells people that you think of them as more than just cogs in the system.

7. Hire empathetic people in the mix. Ego clashes do happen despite best efforts, and you want people who can diffuse tensions and mediate discussions between warring sides. I have personally seen the presence of such people help immensely in standoffs where I believed the only outcome might be a bunch of people walking out saying "I don't need this st in my life".