This is because "pen" has multiple meanings:
* A writing implement: This is the most common meaning.
* A small enclosure for animals: This is less common but still a valid meaning.
Since the word sounds the same in both cases, it's considered a homophone of itself.