Massachusetts has received a $5.3 million federal grant aimed at preventing and combating homelessness.