Habitat destruction and extinction in competitive and mutualistic metacommunities