There’s an example here:
http://codex.wordpress.org/Function_Reference/wp_insert_post
// Create post object
$my_post = array(
'post_title' => 'My post',
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(8,39)
);
// Insert the post into the database
wp_insert_post( $my_post );
‘post_category’ takes an array so you’d want to send it one.
In your example, you don’t create an array – it’s just a string.
$categories="1,2,3,4,5";
This however is an array…
$categories = array( '1,2,3,4,5' );
So this should work:
'post_category' => $categories
For PHP arrays, check out:
http://www.w3schools.com/php/php_arrays.asp
http://us1.php.net//manual/en/language.types.array.php