The issues here are not "tenant" versus "occupant", but rather whether whether the new owner intends to occupy the townhome as his primary residence, and wherther you have a bona fide lease which obligates the new owner to give you 90 days notice under the Protecting Tenants at Foreclosure Act of 2009 which requires that tenants residing in foreclosed residential properties be provided notice to vacate at least 90 days in advance of the date by which the new owner seeks to have the tenants vacate the property. Except where the purchaser will occupy the property as the purchaser's primary residence, the terms of any bona fide lease also remain in effect.
If you and your friend answer the complaint, then at the time of the unlawful detainer trial, the judge will make the determinations of whether you have a bona fide lease and whether the new owner intends to occupy the property as his primary residence.
Otherwise, the new owner only needs to serve a 3-day notice to vacate and proceed with the unlawful detainer on those grounds.
In the meanwhile, your friend can visit you anytime. He is not considered an occupant.