The legislation would prevent a president from gutting the civil service, a move that former President Donald J. Trump attempted and has threatened to revive should he win another term.