Mayor Marion Barry, citing an alarming surge in the prison population, announced yesterday he has shifted his position and now fully supports the federally financed construction of a prison in the District that would be operated at city expense.

In reluctantly ending his longstanding resistance to proposals for a new D.C. prison, Barry joined forces with Sen. Arlen Specter (R-Pa.) and U.S. Attorney Joseph E. diGenova, who have argued for months that a new facility is needed to handle the bulging prison population and to bolster public confidence in the criminal justice system.

The city-operated Lorton Reformatory in southern Fairfax County has suffered chronic crowding. Pressed for space, D.C. corrections officials have been forced to house hundreds of convicted felons at the D.C. Jail, another crowded facility that was built primarily to house persons awaiting trial.

"I'm prepared to support the construction on federal land with federal dollars of a new prison," Barry said in testimony before Specter's D.C. Appropriations subcommittee. "It ought to be in the District of Columbia, on federal land and paid for by federal dollars."

The mayor pledged that the D.C. government would assume the cost of operating the new facility. This was a sharp departure from his position of a month ago, when Barry said he would not stand in the way of others seeking to build a regional federal prison in the District but that the city would not contribute to the cost of building or operating it.

"I believe in paying our way," Barry said yesterday.

The D.C. Department of Corrections, with an annual operating budget of $125 million, spends about $16,000 a year per inmate. Barry has added 1,887 beds at the Lorton complex and has more than doubled the department's operating budget since taking office in 1979.

DiGenova said that before yesterday's hearing, Attorney General Edwin Meese III pledged to help obtain federal funding for a new District prison and to provide immediate assistance to relieve crowding.

The federal Bureau of Prisons, which holds 1,400 prisoners convicted in D.C. courts, has agreed to accept an additional 130 D.C. prisoners.

"We realize, of course, that this is but a stitch in a hemorrhaging prison system," diGenova told Specter's subcommittee.

"In the long term, we repeat: This [Reagan] administration will support financially the building of a new prison within the District of Columbia."

A dramatic three-month surge in arrests and incarcerations in the District has left Lorton and the jail bursting at the seams. There were 3,583 inmates at Lorton yesterday, about 80 more than the prison is rated to hold; and 2,613 inmates at the jail, about double the facility's capacity.

To add to the problem, a recent gas leak incident at Lorton forced about 400 prisoners to double up in temporary quarters.

Also, a federal court order prohibiting overcrowding at the jail, located near Robert F. Kennedy Memorial Stadium, has complicated efforts to house prisoners there.

DiGenova said that the Bureau of Prisons and the Department of Defense, which maintains military detention facilities, may be called upon to provide additional space for District prisoners until the crisis subsides.

The city has estimated it would cost $40,000 to $85,000 per bed to construct a new prison facility. Barry declined yesterday to estimate the cost of a new facility, how many inmates it would hold or where in the District such a facility would be located.

He said he concluded it would not have been "politically possible" to obtain federal support to expand Lorton in the face of growing opposition from Virginia lawmakers who would prefer to see the prison closed.

Barry said that even with construction of a prison in the District, Lorton would continue to operate for the foreseeable future.

Barry's announcement was hailed by Local 1550 of the American Federation of Government Employes, which represents 2,100 correctional employes at Lorton and the jail. Corrections officers contend that the crowding has created unsafe working conditions.

However, D.C. City Council member Wilhelmina J. Rolark (D-Ward 8), chairman of the Judiciary Committee, opposed Barry's proposal, saying city and federal authorities should explore alternatives to incarceration and provide adequate job training programs to deter young people from turning to crime.

Steven Ney, a spokesman for the National Prison Project, a group associated with the American Civil Liberties Union that represents the interests of inmates, agreed that "putting money into more bricks and mortar won't solve the crime problem."

City Council Chairman David A. Clarke said earlier this week that if additional prison facilities are built, they should be at the Lorton complex and not in the District.

However, if city and federal authorities seek to build a prison in the District, Clarke said, no area of the city containing ample federal land should be ruled out.

One site that has been discussed by city and federal officials is Bolling Air Force Base in Southeast.

For years, Barry and his administration have opposed construction of a prison, arguing that the inmate population will gradually decline.

But yesterday, in changing his position, Barry cited a 6.3 percent growth in the city's prison population since December, to a total of 6,197 inmates.