Ibn Abbas explained that when a man died, his male relatives had the greater right to his widow. If one of them wished, he could marry her himself, or they could marry her off to someone else, or they could prevent her from marrying altogether. They held more authority over her than her own family did. So this verse was revealed concerning that practice.
كانوا إذا مات الرجل كان أولياؤه أحق بامرأته، إن شاء بعضهم تزوجها، وإن شاؤوا زوجوها، وإن شاؤوا لم يزوجوها، فهم أحق بها من أهلها، فنزلت هذه الآية في ذلك.