مَرَرْتُ بِإِبْرَاهِيمَ — genitive with fatḥa.
مَرَرْتُ بِزَيْدٍ — genitive with kasra and tanwīn.
Both follow the same preposition, and both are proper names. The ending differs because Ibrāhīm is a diptote while Zayd is fully declinable.
The grammatical governor determines the case, while the noun’s class determines how that case is marked.