Yes, the mechanical mechanism was patented. I can't find any evidence for a software patent.
It looks to be US patent 4466033 which was originally developed for the Lisa's Twiggy drive but adapted for use in the original Mac drive. Here is a quote from the second link:
The Sony 3.5” micro-floppy was uniquely enhanced for the Macintosh by
incorporating performance, capacity and data integrity improvements
which had been prototyped with a 5.25" floppy by way of five
innovations [...] Fifth, the software-controlled floppy clamping and
eject mechanism [Ref-3: '033 patent] - a signature characteristic of
the Macintosh - insured file system integrity upon ejection of the
floppy disk. The one-chip controller in combination with these five
innovations created a fast, high capacity, reliable and low-cost
storage device that was unique to the Macintosh. The Macintosh
micro-floppy is also discussed on pp. 32, 39-42, 54 and 66-68 of the
February 1984 issue of Byte magazine
Here is a quote from the February 1984 issue of Byte magazine, page 39:
In addition to the change to 80 tpi, Apple contracted Sony to modify
the drive in several other ways. Two changes allow the Sony drive to
mimic the behavior of the Lisa "twiggy" drives (which were originally
chosen for use in the Mac): disk ejection under software control and
variable disk-rotation speed. The first change allows the Mac to
ensure that a disk is correctly updated before it is surrendered to
the user (that is, you can't take a disk out of the drive until the
Mac software permits it).
Andy Hertzfeld also corroborates Apple working closely with Sony on the drive in this story, and a later Sony patent filed in 1988 cites the original Apple patent.