A stubborn U.S. merchandise trade deficit soared in June to its second-highest monthly total ever, $15.7 billion, the government reported yesterday.

The size of the June deficit confounded private and government economists who have been predicting a turnaround this year after five years of record deficits.

On the basis of a trade deficit of $81.9 billion for the first six months of the year, economists predicted that the 1987 shortfall is likely to exceed last year's record instead of beginning to decrease as President Reagan's top economic advisers have predicted. Treasury Secretary James A. Baker III, for instance, has argued for months that a turnaround is under way and that the 1987 deficit will be $20 billion to $30 billion less than last year's.

"We are concerned that the trade deficit is not coming down as expected," said White House spokesman Marlin Fitzwater from Reagan's vacation White House in California. "Nevertheless, the value of the dollar and other factors should have a positive impact in the months ahead."

Democratic leaders in Congress, including Senate Majority Leader Robert C. Byrd (D-W.Va.) and House Majority Whip Tony Coelho (D-Calif.), said the continued high trade deficits showed the need for tough legislation, passed in different forms by the House and Senate and due to be worked out in a conference when the recess ends after Labor Day. Rudy Oswald, research director of the AFL-CIO, said the June figures showed "a substantial deterioration" in the U.S. trade posture that hurt American jobs.

"This is going to steel the resolve of Congress for a trade bill, whether it will help or not, and make it more difficult for the administration to veto a bill it doesn't like," said William T. Archey, international vice president of the U.S. Chamber of Commerce.

The continued increase in the trade deficit sent the dollar tumbling on London and New York currency markets. With most traders surprised by the size of the deficit, the dollar slipped below the psychologically important mark of 150 yen in both markets, but later rebounded on concerns that the tanker war in the Persian Gulf would flare up. The dollar is considered an investment haven in times of crisis.

The trade deficit was pushed upward by a record flood of imports, largely manufactured products, although one-third of the $36.8 billion in foreign goods bought by Americans was due to increases both in the price of oil and the amount purchased. June imports were $2 billion higher than the May figures and $33.7 billion higher than the average for the first five months of the year.

Imports of manufactured goods totaled $28.3 billion, $1.4 billion higher than in May and $2.7 billion higher than the five-month average.

The near-record June trade deficit came despite a new method of calculating U.S. sales to Canada that reduced the total shortfall by $608 million. Without that change, which was announced this week by the Commerce Department, the deficit would have been $16.3 billion, the highest on record for a single month. Commerce said that U.S. Customs Service undercounts American exports to Canada and decided to use the Canadian Customs figures instead. Using that system, the Commerce Department reduced last year's record trade deficit by $10.1 billion, from $166.3 billion to $156.2 billion.

June exports hit $21.1 billion, the fourth straight month they had topped the $20 billion mark. But even with that kind of a performance, "We are just not seeing the kind of robust export growth we need," said Stephen Cooney, director of international investment and finance for the National Association of Manufacturers.

The growing trade deficit shocked economists such as Alan Sinai, who had forecast that that shortfall would shrink to $13.3 billion in June after hitting a surprisingly high $14 billion the month before. He said the June data "throws very icy water" on the notion that the trade deficit will improve slowly over the year.

"Those of us who have thought that a turn is in progress have to rethink the idea as a result of the June figures," said Sinai, chief economist of Shearson Lehman Brothers.

His view was echoed by Lawrence Chimerine, chairman of Wharton Econometrics, who called the high deficit "a big setback" and said that if it continues he will have to revise his estimates that the U.S. trade picture "continues to be the major bright spot in the U.S. economy."

The United states once more ran its largest deficit with Japan, $5.4 billion, an increase from $5.1 billion in May. Other deficits were Western Europe, $2.9 billion, up from $2.6 billion; Taiwan, $1.8 billion, up from $1.6 billion; OPEC nations, $1.3 billion, up from $1 billion; South Korea, $1 billion, up from $867 million; Hong Kong, $600 million, up from $469 million; Mexico, $600 million, up from $594 million, and Canada, $531 million, down from $901 million