"Ought not to" is used to indicate that something is not advisable or is a bad idea. The sentence is advising someone that it is unwise to walk home alone late at night.