A Virginia state judge has ruled the state's attorney general improperly sought damages for Virginians who unknowingly purchased Oldsmobiles powered with Chevrolet engines.

Richmond Circurt Court Judge Williard I. Walker held that Attorney General Anthony F. Troy acted two months before a law giving him that authority became effective when he sued General Motors Corp. and 17 Oldsmobile dealers over the sales of certain 1977-model Oldsmobiles.

General Motors, which had been sued by 14 other states before the Virginia suit, has offered to exchange the cars for new ones under certain conditions. The various state suits allege that GM and its dealers violated deceptive trade laws by selling the cars without warning customers of the Chevrolet engines.

An official in Troy's office said yesterday that the Richmond judge has not questioned whether Troy has the right to seek a court injunction blocking deceptive sales practices. The judge also has agreed to hear arguments on a motion that would, in effect, overturn his ruling that the state cannot collect damages on behalf of the automobile purchases.

The ruling does not block individual car owners from suing on their own for damages July 1 gave Troy's office the authority to seek damages, but that was two months after the Oldsmobile suit was instituted.