What I’d forgotten is that Apple had removed this as default behavior a few years ago (I think in MacOS 10.14 Mojave), but you can restore the feature with this hidden preference, typed in Terminal:
[…]
defaults write com.apple.dock slow-motion-allowed -bool YES; killall Dock
Update (2024-10-07): Saagar Jha:
High Sierra, actually.