An Afghan migrant who stabbed a dog walker to death in a random attack has been sentenced to an indefinite hospital order.