From the manga/anime, we do not know how Brooke learned which devil fruit he had eaten, but we can safely speculate on different possible scenarios.
As the answer in the possible duplicate says, there is a "Devil Fruit Encyclopedia" which lists the names and abilities of the known devil fruits (the encyclopedia is not complete). Some devil fruits come with illustrations. This is how Blackbeard was able to identify the Yami Yami no Mi fruit and steal it from his nakama Thatch.
It is possible that the entry for Brook's Yomi Yomi no Mi fruit was illustrated and therefore he knew what the fruit was before he ate it. However, note that this fruit is rather peculiar in that it does not grant any abilities while the user is still alive. Even though this is speculation, this may be the ONLY fruit with that characteristic. Therefore, even if there were no illustrations, one could have identified his fruit by the ability it came with, or lack thereof.
EDIT: (After Kaine's comment)
In chapter 676, when the salamender Slime dies and turns into gas, the powers of the artificial devil fruit he had eaten are re-introduced in a nearby apple. That means that if a devil fruit user dies near another fruit, and that fruit changes shape, one can know which type of devil fruit it is based on the deceased user's powers.