The Pirate Hat unlocks when you gain access to Treasure Island (the 3rd area - unlocks at level 7) and costs 25 Wool. If you do not have a black sheep, you can buy black paint for 10 Wool. If you do not have a male sheep, you can trade a female sheep for one for 3 Petals.
The trophy will unlock as soon as have all the requirements. See the video below for reference.