From the Super Mario Wiki
The Stovepipe Hat is an item in the NES release of Mario's Time Machine. It is a kind of top hat that was famously worn by Abraham Lincoln. In 1862, while Lincoln was in Gettysburg (although his famous Gettysburg Address was in 1863), his hat is stolen by Bowser after he travels back in time to collect famous items across time for his museum. It is then taken back by Mario after he enters the museum and defeats the Koopa Troopas guarding it. Mario brings it with him as he travels back in time to Gettysburg to return it. He then drops it off in front of a gate, and a news article appears that mentions how Abraham Lincoln refused to sign the Gettysburg Address without his hat (again, despite that taking place in 1863).