The current code just copies the most basic settings from the template course, which doesn't include the visibility setting. If you want to copy that setting from the template, edit create_course() in .../enrol/ldap/enrol.php and search for the line that reads:
$course->visible = 1;
and comment it out. That should do it.