Secretary of Defense Caspar W. Weinberger said yesterday that he has run the Pentagon efficiently and that Congress is to blame for any remaining management problems.

Weinberger, who testifed before the Senate Armed Services Committee, was responding to mounting congressional criticism about overcharging for military spare parts, faulty weapons testing and other alleged management problems.

Listing areas where "there remains room for improvement," Weinberger pointed only to problems caused by congressional interference. He urged the passage of two-year military budgets instead of the current annual process and said Congress should give him more "flexibility" in running the Pentagon, closing bases and dealing with contractors. He took credit for uncovering "ridiculous" overpricing of some military supplies and spare parts and for coming up with a 10-point program he said would end such abuses "once and for all."

"I've been a little disappointed that having discovered the bank robbery we stand accused of making it," Weinberger said.

But even as he told Congress that the spare parts price problem has been resolved, a defiant letter from one Pentagon supplier, the Sperry Corp., was disclosed.

After Sperry charged the Navy $110 for a 4-cent diode, among similar big markups, Secretary of the Navy John F. Lehman Jr. wrote Sperry an indignant letter demanding reimbursement.

Sperry Chairman G. C. Probst responded that his investigation found "no evidence to date of improper pricing." Once overhead and other factors are considered, Probst wrote Lehman, the $110 diode and other supply prices are "fully in accord with approved Navy pricing procedures."

Congress has agreed so far to pay for most of the Reagan administration's defense buildup, which could total $1.8 trillion over the next five years. But many pro-defense members of Congress, such as Sen. William V. Roth (R-Del.) and Sen. Charles E. Grassley (R-Iowa), have been raising questions about possible waste in the Pentagon budget.

Both the House and Senate recently voted to create an independent office to oversee weapons testing. The Senate also approved a measure ordering the Pentagon to report to Congress when spare parts prices increase more than a set percentage.

Senate Armed Services Committee Chairman John G. Tower (R-Tex.), who has been a reliable supporter of the military, has scheduled a series of hearings, beginning with yesterday's appearance by Weinberger, to examine how the Pentagon works.

Tower and other committee members said that Weinberger has "performed admirably" as defense secretary. Several senators suggested, however, that the Pentagon has serious management problems.

Sen. William S. Cohen (R-Maine) said the Pentagon has resisted improvements suggested by Congress, and Sen. Carl Levin (D-Mich.) charged that the Pentagon has opposed opportunities to increase competition in military contracting. Sens. Sam Nunn (D-Ga.) and Dan Quayle (R-Ind.) questioned whether Weinberger has managed to control potentially costly rivalries in weapons procurement among the Navy, Army and Air Force.

Weinberger criticized Congress for failing to approve budgets before the start of each fiscal year, and said a two-year budget cycle would help substantially. Quayle and Nunn endorsed the idea, with Nunn suggesting that authorizing and appropriating functions be united in one committee and one bill.