مَرَرْتُ بِزَيْدٍ: bi- is an explicit preposition and Zaydin is its genitive complement.
جَاءَ غُلَامُ زَيْدٍ: ghulāmu and Zaydin form an iḍāfah; Zaydin is mudāf ilayh.
Both examples show Zaydin in the genitive, but the governing relationship differs.
When parsing, identify the explicit preposition or the noun-to-noun construct instead of relying on the kasrah alone.