RICHMOND, AUG. 24 -- Gov. Gerald L. Baliles announced today a $138 million surplus -- the largest in the state's history -- for the fiscal year that ended June 30.

However, the governor cautioned legislators against making plans either to spend it on pet projects or return it to Virginia residents through a tax cut.

Combined with another $16 million surplus projected in the budget for the current fiscal year, the state should enter its new biennial budget term next July 1 with a $154 million surplus, Baliles told members of the General Assembly's money committees.

He urged the legislators not to yield to "the politics of demand," which he said would range from "demands to spend every cent we've got" to the "politically attractive" option of proposing a tax cut shortly before the General Assembly election Nov. 3.

The latter choice, he said, could be "profoundly injurious to the commonwealth's long-term interests."

Although there was no surplus as recently as 1983 in Virginia, the surplus was $31.6 million last year, $47.1 million in 1985 and $81.2 million in 1984.

The District of Columbia government does not report surpluses per se, but includes excess revenue in its budget process to pay off a $220 million deficit left over from a 1980 fiscal crisis. Congress requires that the city allocate $20 million a year toward reducing the deficit, but the actual amount repaid is usually negotiated by the council and the mayor.

Official Maryland figures were not available yesterday, but the state in June projected at least a $100 million surplus because of the change in the federal tax law.

This year's surplus in Virginia reflects a vigorous state economy -- per capita income increased by 6.9 percent last year compared with 5.8 percent nationally. Another factor, Baliles said, was an unexpected surge in revenue in the closing weeks of 1986 as high-income taxpayers divested assets before the new federal tax law increased the tax rate on capital gains.

The phenomena occurred in nearly every state, including Maryland, that bases its in- come tax system on the federal structure, Baliles said.

Baliles quoted Steven Gold, director of fiscal studies for the National Conference of State Legislatures, who cautioned, "I'm afraid this revenue bulge may produce a false sense of euphoria. To the extent that it is due to capital gains, it may just be borrowing from the future."

Baliles noted that legislators already have called for more than $100 million in new spending for mental health.

He said additional funding also is being requested for child care programs, Medicaid, prenatal care, toxic waste cleanup, natural resource protection, a Southwest Virginia economic development initiative, housing, tourism, local health program and volunteer rescue squads.

Some Republicans, dusting off a debate from this year's General Assembly session, said part of the surplus can be attributed to a windfall from changes in the federal tax structure and should be returned to the taxpayers.

"None of this money has anything to do with the windfall," said Del. Warren G. Stambaugh (D-Arlington), the chief architect of the state's windfall rebate law that reduced individuals' state income taxes by $144 million for the fiscal year that began July 1. An additional $29 million was held in reserve, in case the windfall was less than anticipated.

Stambaugh agrees with Republicans that the windfall will be substantially larger than originally anticipated.

However, he contends that the appropriate time to decide whether or how it should be returned is during the 1989 session of the legislature, after next year's tax returns can be analyzed.

Possible methods of returning the surplus that have been discussed include a simple reduction in tax rates, changes in tax brackets and the elimination of the state sales tax on food.

The windfall legislation was approved despite Republican objections that more of the windfall should have gone to middle- and upper-income taxpayers, whose state taxes increased more than those lower-income taxpayers because of changes in the federal law. They said the Democratic plan returned a disproportionately large amount of the windfall to low- and middle-income residents.

Del. Vincent F. Callahan Jr. (R-McLean) agreed that "this is not the time" for a decision.

He said that as a percentage of the current $19.7 billion two-year budget, "this probably isn't a record" surplus.

Callahan claimed the large surplus is "directly attributable to Regean administration" spending that has helped high-tech industries in Northern Virginia and military installations in Tidewater.

Lt. Gov. L. Douglas Wilder, who has pushed to remove the state sales tax on food, said in a speech Saturday that "the large state surplus demonstrates that our work from the last legislative session is still not completed . . . . None of the so-called windfall should be kept by state government to spend."