you cant use foreach as with the same variable 😉
but your real problem is probably here:
'key' => 'section_contents', //this is the post relationship field, which is in a repeater subfield of 'toc_section'
subfield of repeater
if you have luck change this too and it works:
key' => 'toc_section_%_section_contents',