A federal appeals court has temporarily blocked a San Francisco hospital's attempt to drop Social Security coverage for its employes, giving a labor union and the National Labor Relations Board an early victory in what promises to be a nationwide legal struggle over similar attempts by other hospitals and nonprofit organizations.

The U.S. Court of Appeals in San Francisco directed the Internal Revenue Service not to act on the application of Ralph K. Davies Medical Center to terminate Social Security. The hospital's participation in the program would have come to a halt Wednesday, the end of a mandatory two-year waiting period, but the court directed that the withdrawal be stayed until it can hear full arguments in the case.

According to the Social Security Administration, 739 hospitals and nonprofit organizations and 412 state and local governments have given notice of their intention to eliminate Social Security coverage for their workers by 1984. Most of them are trying to cut costs by escaping from the Social Security tax and substituting lower-cost, privately run benefit plans, hospital industry experts say.

The San Francisco court did not rule on those arguments, but directed that the hospital workers be kept in the Social Security program until it has done so.

Federal law provides that nonprofit organizations and state and local governments may drop out of Social Security after eight years of participation. No consultation bargaining with employes is required. Rep. J.J. Pickle (D-Tex.) is promoting an amendment to the law to close this escape hatch, but it has been tied up in the House.