As mentioned in the comment, Dr. Vegapunk's scientific expertise is the logic behind an inanimate object being able to "consume" a devil fruit.
Dr. Vegapunk covered exactly how Devil Fruit powers are transferred over to a user, and was the scientist behind the method of adding Devil Fruit powers to inanimate objects, such as swords and guns.Source
This is the only known research paper of his related to this experiment:
The inanimate objects who have eaten Devil Fruits are:
It is also notable that the only Devil Fruits shown to be capable of achieving such a feat are Zoan devil fruits. It may be because Logia and Paramecia only grant the users supernatural powers, which would not bring the objects to life.
This is all that is known about the matter.
According to Oda, a "certain professor" will explain the complex mechanisms behind all of the Devil Fruits in the series in the near future. Source