The 27-year-old was due to remain with Shrewsbury and help them try to avoid relegation but will now join Yeovil's fight against the drop.
Speaking to Shrewsbury's website, manager Mike Jackson said: "I had a call from Sam yesterday saying that he had spoken to [Yeovil boss] Gary Johnson about going back as they have a few injuries.
"They are also thinking towards next season and I had a conversation with Gary and he said he's like Sam back there.
"It's not ideal for us but we wish Sam well and thank him for what he's done during his time here, he's been great around the place, he's a good character, a great lad and I hope he goes back there and it works out."
Foley made nine appearances in the month that he spent with Shrewsbury.
Yeovil go into the last four games of the season five points adrift of safety in the Championship.