Mechanical compatibility measn that the chips may be inserted into the same slot.
Pin compatibility means the same pins, for instance pin 5, perform the same functions on both chips.
Electrical compatibility means that for a given pin function, such as A0, the voltage levels are the same on both devices.
Chips may come in various packaging styles such as QFP, CerDIP, etc. The chips woudl be pin and electrically compatible, btu not mechanically compatible, since the different packing styles are for different socket/circuitboards.
Chips could be machanically and electrically compatible, but not pin compatible. For instance the Athlon and Pentium 4, which have the same voltages, and the same functions, but have those functions assigned to different pins.
Chips may even be mechanically and pin compatible but not electrically compatible if they use different voltages for the inputs and outputs. In some cases, one chip may be compatible with the other, but not the other way around, for instance the 74Cxx family can be used in circuits designed for the 74HCTxx series, but the 74HCTxx series cannot be used in 74Cxx circuits because the 74Cxx series circuit may be designed to use a voltage higher than the HCT family can handle.