Williams, 19, has made four appearances for Castle this season after returning to the club following his release by Morecambe.
The left back had spent some time with Palace in the summer before injury cut short that stint, and he was offered a six-week trial recently.
The club said: “Having returned to Castle at the start of the season he was offered a six week trial at Palace during which time he impressed enough to be offered a deal. Everyone at Newcastle wishes Josh all the best for the future.”
Keep up-to-date with our exclusive email newsletters.
Subscribe