A Federal district judge has ordered the Missouri Knights of the Ku Klux Klan to stop playing racist telephone recordings that imitate the children's television program ''Mister Rogers's Neighborhood.''

The judge, Howard F. Sachs, also ordered the Klan and three of its members on Wednesday to turn over tape recordings and other materials. Lawyers for ''Mister Rogers'' say the materials infringe on the program's trademarks and copyrights. The judge set a hearing in the case for Oct. 20.

Judge Sachs issued the temporary restraining order one day after Fred M. Rogers and his company, Family Communications Inc., sued to stop the Klan's use of the recording.

The message imitates the sound effects and song of the program and Mr. Rogers's voice and speech patterns. On the first tape, the Mr. Rogers impersonator points out a black youngster on a playground and calls him a ''nigger drug pusher.'' At the end of the tape, the Klan lynches the youth. In a second tape, the Mr. Rogers impersonator ridicules homosexuals and says, ''AIDS was divine retribution.''