EVERYONE backstabs if you are winning and lower than average on army. I don't think there is an exception. If they see weakness or see you as too powerful they want to take you down. If they see both it is like holding candy up in front of them--they can't resist. Humans play the same way with the AI. If you are middle of the road most of the game you might be able to avoid this.
Try any of these and you'll get DOW's even out of friends:
1. Good friends but ICSing rapidly? Almost all AI hate it, they'll DOW you, even backstab to stop you.
2. Forward settle them? Especially right next to their capital? Repeatedly settle new cities on your border with them? War is only a matter of time friends or not.
3. Wondermonger but keep a weak army? More likely to backstab if you get wonders they were prioritizing but ANY wonders, especially a lot in a row, and they may try it. Almost a matter of course if you keep a weak army.
Friendships are a matter of convenience. If you compete with them tangibly they don't like it. You can't ever count on a friendship giving you protection and had best keep up that army even if you have one neighbor bordering who is friends. Too many backstabs have taught me the AI has no qualms about striking despite how they appear. If they have nothing better to do you'll get a backstab. This is why it is important to keep your friend occupied. If it is you and them against enemies there is almost 0 chance they will attack you. Form and encourage cliques. If everyone is too nice pay warmongers to attack your friend then defend them. It's stupid, but the only surefire way I've found of creating lasting friendships. Those first offers mean squat until you have a common enemy. Then they ACTUALLY feel they need you. Even if you keep a weaker army they will hesitate to attack you if you are banded together against an outside threat--thinking the other AI will take advantage of the divide. They are paranoid and greedy--use it against them.