How to get the result of comments_number() as a string instead of printing it out?

Easiest way:

ob_start();
comments_number();
$data = ob_get_clean();

$data will contain the text.