See Two-factor authentication for Apple ID https://support.apple.com/en-us/HT204915 See this section especially Setup two-factor authentication for your Apple ID. From this section, "Two-factor authentication is available for Apple ID accounts with at least one device that's using the latest iOS, iPadOS, or macOS. Learn more. You can follow these steps on your iPhone, iPad, or iPod touch to turn on two-factor authentication."
Note that, even though the latest iOS, iPadOS, or macOS devices are mentioned above, sometimes two-factor authentication is not available. "While most iCloud users can now turn on two-factor authentication, certain account types may still be ineligible at Apple’s discretion." See Availability of two-factor authentication for Apple ID https://support.apple.com/en-us/HT205075.
Note that it is unclear when or why Apple might exercise it "discretion" in regard to the availability of two-factor authentication.