Use the PHP bbcode tags properly and you'll see why:
$sql = 'INSERT INTO cat_relations(relation_user_id,relation_cat) VALUES($ID,$_POST['categories'][$x])';
(Then again, you should be using an editor with syntax highlighting anyway....?)
Obviously, the array reference at the end is what breaks the string. Not only that, but since you're using single quotes as your string delimiter, the string isn't even being parsed for variables (so $ID is left as a literal dollar sign followed by ID).
I would suggest you read up on how to form a [man]string[/man] properly. I would also suggest you use concatenation when referencing arrays:
$string = 'This is my array: ' . $myArray['test'] . ' !';
Also, do you mean that this query is in a loop, executed several times? If so, you could improve the efficiency and reduce overhead by running one single INSERT query that inserts multiple rows, ex.
INSERT INTO myTable VALUES('row1', 'value1'), ('row2', 'value2'), ('row3', 'value3'), ...