The forecastle of a ship is in the forward part of a ship — at the front, not the back. Looking at renderings of cogs, the 'castle' at the stern seems more to anticipate the modern bulk carrier, with an accommodation block with bridge on top at the aft end, looking out over the cargo holds.
Ships of that era and leader had castles on both ends fore and aft. It's just the forward one than retained in usage as a sailing term, even after foredecks no longer looked like castles. The aft castle became a quarterdeck, a poop deck, a cockpit or a bridge etc.
Meanwhile, a built-up and elevated stern 'castle' is advantageous place to put the steering and command position, close to the rudder and with visibility of the whole ship, it's rig, plus where the ship is going. While maximizing mid-ship area for cargo. If you have to pick one end or the other, stern is the more comfortable end of the ship being most sheltered from wave action and weather. Being elevated and fortified also helps as a fighting/defensive position, but that is less important for modern cargo ships. 'Anticipation' isn't quite the right word as shipbuilders have always worked within the same basic design considerations and trade-offs, as the sea itself continues to enforce the same fundamental constraints.