هَذَا غُلَامُ زَيْدٍ: ghulāmu is a nominative predicate; Zaydin is genitive mudāf ilayh.
رَأَيْتُ غُلَامَ زَيْدٍ: ghulāma is an accusative object; Zaydin stays genitive.
مَرَرْتُ بِغُلَامِ زَيْدٍ: ghulāmi is genitive after bi-; Zaydin stays genitive.
The mudāf changes its own case according to its sentence position; the mudāf ilayh is genitive throughout.