Modern Warfare 2 owners must purchase Modern Warfare 3 separately; owning one does not grant access to the other. However, certain content from MW2 will transfer to MW3 and Warzone, regardless of the previous title's ownership. Currently, there is no distinct advantage to owning both MW2 and MW3.
Modern Warfare 3 is free on PS5, and Xbox.