Donatello's david wears a bonnet to represent david being a shepherd and the sculpture being created in florence italy
Or it could be the fact the creation was very frowned upon as donatello spent alot of time with his young model although it was unknow if it was sexual or not
Hope some of this helped you