This meaning of ため is used to refer to someone who is the same in terms of age or social status, equivalent to a peer or someone in a similar category.
ためになるto be beneficialためにfor the sake ofともだち友達のためfor the sake of a friendおなじ同じためof the same peer groupためをおもって思ってthinking of someone’s benefitためにつくす尽くすto devote oneself for someone's benefitまなぶ学ぶためfor the purpose of learningためにはたらく働くto work for the sake ofなかま仲間のためfor the sake of companionsがくねん学年のためfor the sake of the same grade level