The Intel Core i5-14600K wins in 10 out of 14 comparable specs, with 1 tie. Its biggest advantage is L2 Cache (1233% better).
Core i5-8400 wins in 3 specs (Max Turbo Power: 64% better).
Recommendation
Choose Core i5-14600K if you want the best overall performance — especially l2 cache.
Choose Core i5-8400 if max turbo power matters more to you.