How do I get a version of Android with linux kernel >= 3.18 on a Nexus 5?
Android devices generally don't receive major kernel upgrades, and Nexus devices certainly never did. Even when OS upgrades take place they only get minor-version kernel patches. The table in the other question is intended to represent what a new device would ship with given the first version of Android it supported, but even that is not a hard-and-fast rule.

For your specific example, Google has no code for either the N5 or N6 with a 3.18 kernel. Both remained on their original major versions (3.4.y and 3.10.y, respectively) for their entire lifetimes. You can check the "hammerhead" and "shamu" related tags in the kernel/msm repo to verify this. If you need a newer kernel on one of those devices you're likely going to have to port it yourself, unless you can find another 3rd party that already undertook this work.