An attempt to exempt members of Congress and political appointees from a proposed pension tax change could spell trouble for millions of federal workers, state and local government employes and teachers who face an unexpected early tax bite when they retire.

The House Ways and Means Committee tentatively has approved a change that would eliminate the post-retirement tax-free period for people who contribute toward their pensions. But the proposal would not cover members of Congress and certain political appointees, although they are covered by the federal retirement program.

Currently, federal employes put 7 percent of their salary into the civil service retirement fund. Because they already have paid taxes on their contributions, as part of salary, their annuities are not taxed after they retire until they have recovered all their contributions. Many state and local government workers and teachers who contribute to their pension plans benefit from this post-retirement tax-free period. For the average government worker this period lasts about 18 months, but it can run as long as three years.

The House committee has proposed a change in tax laws so that persons retiring after July 1 of next year would begin paying taxes immediately on part of their annuity. The action would eliminate the tax-free period.

Federal and postal workers had hoped that the proposal would be dropped from the tax plan, because it also would hit members of Congress -- including House Speaker Thomas P. O'Neill Jr. (D-Mass.) -- who plan to retire in 1987.

But the Ways and Means Committee has agreed to an amendment to its pension tax plan that would, in effect, exempt virtually all current members of Congress and most political appointees. Federal and postal workers still would be subject to the immediate pension tax, but legislators and political appointees would not.

This week, Reps. Stan Parris (R-Va.), Frank R. Wolf (R-Va.), Steny H. Hoyer (D-Md.) and others plan to go before the House Rules Committee to ask for permission to offer an amendment to take the pension tax plan out of the final tax reform bill. Rep. Vic Fazio (D-Calif.) will be lobbying Democratic colleagues to exert pressure to drop the proposal.

Parris and Wolf have warned that the pension tax, if it becomes law, could force thousands of government workers to retire early next year. They estimate that 210,000 senior federal employes, including 50 percent of all government executives and 42 percent of the government's scientists and engineers, are eligible to retire.