How do commands like fdisk -l find the sector size?

A device’s sector size isn’t stored in the MBR.

User space commands such as fdisk use the BLKBSZGET and BLKSSZGET ioctls to retrieve the sector sizes from disks. Those ioctls are handled by drivers in the kernel, which retrieve the relevant information from the drives themselves.

(There isn’t much documentation about the relevant ioctls; you need to check the kernel source code.)

You can see the relevant information using other tools which query drives directly, for example hdparm. On a small SSD, hdparm -I tells me

[...]
Logical  Sector size:                   512 bytes
Physical Sector size:                   512 bytes
Logical Sector-0 offset:                  0 bytes
[...]
cache/buffer size  = unknown
Form Factor: 2.5 inch
Nominal Media Rotation Rate: Solid State Device
[...]

On a large spinning disk with 4K sectors, I get instead

[...]
Logical  Sector size:                   512 bytes
Physical Sector size:                  4096 bytes
Logical Sector-0 offset:                  0 bytes
[...]
cache/buffer size  = unknown
Form Factor: 3.5 inch
Nominal Media Rotation Rate: 5400
[...]

There are a few questions in there, I tried to track down the answer to "Where does fdisk find the sector size of a disk?" The best I've found is that it gets the info from ioctl.

ioctl info on Wikipedia and Linux man page.

fdisk source code link