Jess - you might be seeing this because:
1) the town homes are smaller - in general, the smaller the home, the larger the price per square foot;
2) the town homes have nicer finishes - slab granite on the countertops, travertine in the baths, etc does not make the townhome any larger but it does increase the cost to build it;
3) the townhomes have very nices amenities included within the community so people will pay more to live there (for example, may be there is a very nice fitness center, multiple pool complex, 24 hour emergency care response, extra security, golf course privileges, etc) - if the single family homes do not have these amenities, then the price per square foot on the town homes potentially is higher;
4) the townhomes have attached enclosed garages and/or basements and the single family homes do not - garages and basements in my area are not included in the square foot field so the price per square foot would not reflect these area which clearly have value.
5) Because you said they were within the same community I suspect this is remote but maybe the schools are different and/or taxes are significantly different.
I hope that helps; others on this forum will probably be able to give you more ideas.