It is indeed part of the New York City subway. It is the former-IRT "7 Flushing" line.
This line is former IRT and parts were built in coordination of competitor BMT, both private companies unlike the municipally-owned IND. Eventually the city bought out all the subway companies, creating one municipal system.
By the time it was built, lower/mid Manhattan residents had experienced more than enough elevated trains, in particular they were tired of those powered by steam; and they wanted the loud, ugly, filthy things gone. Electrification became possible around 1890, and railroads built in NYC needed to be electrified.
The IRT's claim to fame was that the parts of the line downtown run underground. (which isn't really feasible for steam, although London gave it a serious try.) They switch to elevated structures out in the boroughs where land values are lower, but it remains electrified. This subway section opened first in 1915, and it was extended outward into Queens, finishing 12 years later.
By this time, railroads everywhere saw electrification as "the way to go" if one could afford the significant costs of installation. Those costs are reasonable if the railroad is very short and very busy, as this one is.
The line is 102 years old - older than virtually all of the buildings. If a building had been in the way of building the line, then depending on cost the either the building would be bought out, or the line would be rerouted. Railroads also have power of eminent domain to take property they need, as do cities.
Buildings built under the elevated structures are not unheard of in New York City, but they certainly came after construction. A 1-2 floor building simply would not have enough real estate value to justify the considerable expense of building around a structure.