This is because you must have signed in earlier and enabled Find My on your iPhone, which also turns on Activation Lock. If you didn't have Find My enabled, you can factory reset your iPhone without needing an Apple ID. But that also means anyone could wipe and use your phone if it were to get stolen. The same thing applies to the Mac.
You can certainly use a Mac without an Apple ID, but you'll miss out on a lot of features that make the Apple ecosystem great...iPhone Mirroring, notifications from iPhone on Mac, Sidecar, Universal Clipboard, Universal Control, FaceTime, iMessage, text message forwarding, etc. And then of course all the iCloud features to sync things between devices....passwords, bookmarks, notes, reminders, photos, calendar, contacts, etc.