Why is the Slavic second palatalization took place before PIE *aj (Proto-Slavic *ě), but врагъ (vragŭ, enemy) / враѕи (vradzi, enemies), where vradzi is a PIE *ey (Proto-Slavic *i)?
You probably took the description of the second Slavic palatalization from some simplified description. It isn't the case that it would only happen before ě (yat') and not before i. It happened before both.
The ě and i were the results of the monophthongization of *oi or *ai (if these two were actually distinguished at all). In Monophthongization of diphthongs in Proto-Slavic you can read:
While most cases of older *ai developed into *ě₂, some inflectional endings appear to have developed *i₂ instead. It is unclear what factors are involved in triggering one reflex versus the other.
-The o-stem nominative plural (Old Church Slavonic člověkъ, člověci), reflecting the original Proto-Indo-European pronominal ending *-oy, also seen in Lithuanian -ai.
-The thematic imperative infix (Old Church Slavonic rešti, rekǫ, reci), reflecting the original Proto-Indo-European infix *-oyh₁-.