For years Washington tourists have wondered how they could slip into the Pentagon and July 1 the sight-seers discovered the way. The secret is to take Metro.

Barely two months after Washington's new subway system was extended to the Pentagon, the number of tourist gawking along the once-closed corridors of the huge five-sided building and shopping for bargains in its price-controlled shopping mall has grown dramatically.

What's more, the 34-year-old building's transformation may be just beginning. On Tuesday scores of Washington-bound buses from the Virginia suburbs will abruptly terminate their runs at the Pentagon, forcing thousands of commuters to duck into the pentagon Metro station to catch a train bound for the District.

The changes will make the Pentagon - along with the Rosslyn subway station - into one of the largest transportation terminals in the country, according to Metro officials. Each work day, an estimated 4,500 commuters will be left by huses at the Pentagon, a number that will be exceeded only by the 5,000 commuters expected to be dropped at the Rosslyn station.

The Pentagon already is a transportation terminal for its own 22,000 employees almost half of whom take public transportation to work. They wait for their buses in long orderly lines, know the bus schedules to the minute, and operate the subway fare collection equipment with authority.

At the Pentagon, the additional influx of commuters is likely to bring more dramatic changes than at other subway stops. Riders will discover part of the Pentagon known to few Washington residents - and Pentagon workers are likely to see their small shopping center transformed into a place that one visitor compared Friday to New York's Grand Central Station.

Assuming the bus riders deposited at the Pentagon follow the practice of many of the subway's current riders, the nation's generals and admirals also many find themselves standing in unaccustomed lines for their $2,25 haircuts, 50-cent shoeshines, and 55-cent-a-pack cigarettes.

Some Defense Department officials like the image of a closed, almost forbidding facility that the Pentagon acquired during the era of Vietnam War protests. They aren't looking forward to more tourists or more shoppers. "We don't want those people to come in," said John Horn, executive secretary of a Pentagon committee that controls the shopping area. "These faicilities are just for the people who work here."

But as the mall's 16 retail merchants gleefully protest and Horn admits, "If they come in, they can shop, too." And that is exactly what many of the merchants say is happening.

Just how many have come in thus far is difficult to ascertain, but August was the biggest month ever for the Pentagon's guided tours and most merchants on the concourse report their sales last month, usually a poor sales period, ran ahead of 1976 levels. The reason, all agree, is largely Metro.

The Pentagon's tourist influx is not anywhere near the 149.600 visitors that the White House attracted last month. Nevertheless, Pentagon officials say thet the 10,209 visitors who took the guided tour of their building last month represent a respectable start for "the brand new kid on the block." After all, added Air Force Capt. Douglas Jacobsen, who designed the building's 50-minute tour as a temporary bicentennial project, other tours are better publicized and known to the public.

Despite the Pentagon's sprawling, 11,000 space parking lot, visitors traditionally have been reluctant to visit the building because of a lack of visitor parking spaces. Buses have long used the Pentagon's three basement-level bus bays, but the bus service was never convenient enought to encourage tourists to stop by the building, Jacobsen said.

Metro has changed all that, Pentagon merchants say. Now with the building only 12 minutes and a 40 centride from major established tourist attractions in downtown Washington, more and more "strange faces," as one Woodward and Lothrop sales manager put it, are venturing into the Pentagon.

This is ringing strange bells here," added a salssmand in another specialty shop that is located only a 50-second escalator ride from the Pentagon Metro station. "You wouldn't believe the people that come to this building. . . . There is a mystery here and the response has been fantastic. It's going to be a real addition to the tourist business in Washington," he said.

Some of the increase has caught some merchants by surprise. Demand for tourist trinkles has been sharp, says a Walgreens drug store official, who is selling coffee cups with a sketch of the Pentagon for $2.50 each. So many tourists have been asking for photos of the insided corridors where tourists cameras are not permitted that a camera shop has begun investigating the possibility of mass producing some.

Although the Pentagon tours lackone or two amenities - only 2 of the buildings's 285 bathrooms are open to the public, and there is no place for the public to eat - still, the "mystique" of the building is likely to draw many there. One attraction is to watch young military tour guides walking their way backward along the corridors. An officer who planned the tour said the guides walk backward to maintain "eye contact" with members of their group, but others suggest that the guides are fearful one of the tourists might stray into a secured area.

Actually, some of the Pentagon's most revealing scenes come not on the tour, but in the concourse. There visitors can find a government bookstore where a CIA-prepared Atlas of the Indian Ocean is a current bestseller at $6.50. The mall also features the smallest Woodies department store in the chain. which recently dropped its men's wear in favor of women's clothing, a decision that a store official said reflects the growing number of women in the military. A barber shop displays autographed photographs of 60 military and political leaders who had their hair cut in the shop.

Among the photographs on the wall are those of Presidents John F. Kennedy and Dwight D. Eisenhower and Gens. Douglas MacArthur, Omar Bradley and George S. Brown, the current chairman of the joint chiefs. Brown's autographed note praises Pentagon barber Donald Abbate "for a few minutes of relaxation each week."

Abbate is running a 17-barber shop that is the successor to one his father had run at the Pentagon since the building opened in 1943. Most of the merchants are required to pay a percentage of their sales in return for a three-year lease that gives them an option for an extention if the Pentagon's seven-member concessions committee finds their services have been "satisfactory."

Last year the merchants handled nearly $13 million worth of sales and paid the government $280,000 for their spaces. The spaces have become highly prized and concessions committee secretary Horne says he regularly rejects three to five applicants a week for new stores. None is planned, he said.

Nor has the committee been anxious to let the merchants build up their business bu encouraging outsiders to come into the building. Only three yeats ago the committee finally agreed to let the merchants list their telephone numbers in a public phone book and to allow the merchants to advertise in the Pentagon's newspaper.

It still keeps controls on prices the merchants are allowed to charge for services, such as haircuts and shoeshines, and prices on some products, such as cigarettes and cigars. The committee has never attempted to ban a magazine, but newsstand manager William Donnis says "Hustler" magazine would probably be banned if he tried to sell it. "We have never handled it and don't intend to," he added.