Pembrolizumab With Rituximab or Obinutuzumab in Treating Patients With Relapsed or Refractory Follicular Lymphoma or Diffuse Large B Cell Lymphoma

This phase II trial studies how well pembrolizumab with rituximab or obinutuzumab work in treating patients with follicular lymphoma or diffuse large B cell lymphoma that has come back (recurrent) or does not respond to treatment (refractory). Immunotherapy with monoclonal antibodies, such as pembrolizumab, may help the body's immune system attack the cancer, and may interfere with the ability of tumor cells to grow and spread. Rituximab and obinutuzumab are monoclonal antibodies. They bind to a protein called CD20, which is found on B cells (a type of white blood cell) and some types of cancer cells. This may help the immune system kill cancer cells. Giving pembrolizumab with rituximab or obinutuzumab may help kill more cancer cells in patients with follicular lymphoma or diffuse large B cell lymphoma.

OUTLINE: Patients are assigned to 1 of 3 arms.

ARM I:

INDUCTION: Patients diagnosed with R/R FL receive pembrolizumab intravenously (IV) over 30 minutes on day 1. Treatment repeats every 3 weeks for 4 cycles in the absence of disease progression or unacceptable toxicity. Patients also receive rituximab IV on days 1, 8, and 15 of cycle 1, and on day 1 of cycle 2.

EXTENDED THERAPY: Patients with at least a partial response receive pembrolizumab IV over 30 minutes on day 1. Cycles repeat every 3 weeks for up to 2 years (35 cycles) in the absence of disease progression or unacceptable toxicity.

ARM II:

INDUCTION: Patients diagnosed with R/R DLBCL receive pembrolizumab intravenously (IV) over 30 minutes on day 1. Treatment repeats every 3 weeks for 4 cycles in the absence of disease progression or unacceptable toxicity. Patients also receive rituximab IV on days 1, 8, and 15 of cycle 1, and on day 1 of cycle 2.

EXTENDED THERAPY: Patients with at least a partial response receive pembrolizumab IV over 30 minutes on day 1. Cycles repeat every 3 weeks for up to 2 years (35 cycles) in the absence of disease progression or unacceptable toxicity.

Arm III:

INDUCTION: Patients diagnosed with R/R FL receive pembrolizumab IV over 30 minutes on day 1. Treatment repeats every 3 weeks for 4 cycles in the absence of disease progression or unacceptable toxicity. Patients also receive obinutuzumab IV on days 1, 8, and 15 of cycle 1, and on day 1 of cycle 2.

EXTENDED THERAPY: Patients with at least a partial response receive pembrolizumab IV over 30 minutes on day 1. Cycles repeat every 3 weeks for up to 2 years (35 cycles) in the absence of disease progression or unacceptable toxicity. Patients with stable disease or better, who are experiencing clinical benefit in the judgment of the investigator, may receive obinutuzumab IV on day 1 of cycles 5, 9, 13, 17, 21, and 25.

After completion of study treatment, patients are followed up for 90 days.

Eligibility Criteria:
Inclusion Criteria:

* Have relapsed/refractory DLBCL or relapsed/refractory FL

  * For DLBCL, patients must have relapsed after, declined, or considered ineligible for high-dose chemotherapy and autologous stem cell transplantation
  * For FL, in addition to relapsed/refractory disease status, patients must have received therapy with CD20 antibody-directed therapy, and must have an indication for treatment; FL eligibility also requires patients have no standard options with curative potential, nor options with more favorable risk/benefit ratio in the judgment of the investigator
  * For FL Arm C (obinutuzumab + pembrolizumab), patients must have relapsed/refractory disease after rituximab-containing therapy including:

    * Rituximab in combination with chemotherapy (at 1 prior line) or
    * \>= 2 prior lines of therapy
    * Patients may have no standard options with curative potential, nor options with more favorable risk/benefit ratio in the judgment of the investigator
* Be willing and able to provide written informed consent/assent for the trial
* Have measurable disease (1.5 cm or greater in the longest diameter of nodal or extranodal disease)
* Have a performance status of 0 or 1 on the Eastern Cooperative Oncology Group (ECOG) performance scale
* Absolute neutrophil count (ANC) \>= 500/uL (within 28 days of cycle 1 day 1)

  * Growth factor and/or transfusion support is permissible to stabilize participant prior to study treatment if needed
  * No lower limit if cytopenia is related to bone marrow involvement
* Platelets \>= 25,000/uL (within 28 days of cycle 1 day 1)

  * Growth factor and/or transfusion support is permissible to stabilize participant prior to study treatment if needed
  * No lower limit if cytopenia is related to bone marrow involvement
* Hemoglobin \>= 8 g/dL (within 28 days of cycle 1 day 1)

  * Growth factor and/or transfusion support is permissible to stabilize participant prior to study treatment if needed
  * No lower limit if cytopenia is related to bone marrow involvement
* Serum creatinine =\< 1.5 X upper limit of normal (ULN) OR measured or calculated creatinine clearance (glomerular filtration rate \[GFR\] can also be used in place of creatinine or creatinine clearance \[CrCl\]) \>= 30 mL/min for subject with creatinine levels \> 1.5 X institutional ULN (within 28 days of cycle 1 day 1)

  \*\*Creatinine clearance (CrCl) should be calculated per institutional standard
* Serum total bilirubin =\< 1.5 X ULN OR direct bilirubin =\< ULN for subjects with total bilirubin levels \> 1.5 X ULN (within 28 days of cycle 1 day 1)
* Aspartate aminotransferase (AST) (serum glutamic-oxaloacetic transaminase \[SGOT\]) and alanine aminotransferase (ALT) (serum glutamate pyruvate transaminase \[SGPT\]) =\< 2.5 X ULN OR =\< 5 X ULN for subjects with liver involvement by lymphoma (within 28 days of cycle 1 day 1)
* International normalized ratio (INR) or prothrombin time (PT) =\< 1.5 X ULN unless subject is receiving anticoagulant therapy as long as PT or partial thromboplastin time (PTT) is within therapeutic range of intended use of anticoagulants (within 28 days of cycle 1 day 1)
* Activated partial thromboplastin time (aPTT) =\< 1.5 X ULN unless participant is receiving anticoagulant therapy as long as PT or PTT is within therapeutic range of intended use of anticoagulants (within 28 days of cycle 1 day 1)
* Female subject of childbearing potential should have a negative urine or serum pregnancy within 72 hours prior to receiving the first dose of study medication; if the urine test is positive or cannot be confirmed as negative, a serum pregnancy test will be required
* Female subjects of childbearing potential must be willing to use an adequate method of contraception; contraception, for the course of the study until at least 12 months after the last dose of study medication

  \*\*Note: Abstinence is acceptable if this is the usual lifestyle and preferred contraception for the subject
* Male subjects of childbearing potential must agree to use an adequate method of contraception starting with the first dose of study therapy until at least 12 months after the last dose of study therapy

  * Note: Abstinence is acceptable if this is the usual lifestyle and preferred contraception for the subject

Exclusion Criteria:

* Is currently participating and receiving study therapy or has participated in a study of an investigational agent and received study therapy or used an investigational device within 4 weeks of the first dose of treatment
* Has a diagnosis of immunodeficiency or is receiving systemic steroid therapy or any other form of immunosuppressive therapy within 7 days prior to the first dose of trial treatment, except for physiologic corticosteroid replacement therapy for adrenal or pituitary insufficiency which is permitted
* Has a known history of active TB (Bacillus tuberculosis)
* Hypersensitivity to pembrolizumab or any of its excipients
* Has had a prior anti-cancer monoclonal antibody (mAb) within 4 weeks prior to study day 1 or who has not recovered (i.e., =\< grade 1 or at baseline) from adverse events due to agents administered more than 4 weeks earlier
* Prior allogeneic transplant, within the last 5 years
* Has had prior chemotherapy, targeted small molecule therapy, or radiation therapy within 2 weeks prior to study day 1 or who has not recovered (i.e., =\< grade 1 or at baseline) from adverse events due to a previously administered agent

  \* Note: Subjects with =\< grade 2 neuropathy are an exception to this criterion and may qualify for the study

  \* Note: If subject received major surgery, they must have recovered adequately from the toxicity and/or complications from the intervention prior to starting therapy
* Has a known additional malignancy that is progressing or requires active treatment; exceptions include basal cell carcinoma of the skin or squamous cell carcinoma of the skin that has undergone potentially curative therapy or in situ cervical cancer
* Has known active central nervous system (CNS) metastases and/or lymphomatous meningitis; subjects with previously treated brain metastases or lymphomatous meningitis may participate provided they are stable (without evidence of progression by imaging for at least four weeks prior to the first dose of trial treatment and any neurologic symptoms have returned to baseline), have no evidence of new or enlarging brain metastases, and are not using steroids for at least 7 days prior to trial treatment
* Has active autoimmune disease that has required systemic treatment in the past 2 years (i.e. with use of disease modifying agents, corticosteroids or immunosuppressive drugs); replacement therapy (e.g. thyroxine, insulin, or physiologic corticosteroid replacement therapy for adrenal or pituitary insufficiency, etc.) is not considered a form of systemic treatment
* Has known history of, or any evidence of active, non-infectious pneumonitis/interstitial lung disease
* Has an active infection requiring systemic therapy
* Has a history or current evidence of any condition, therapy, or laboratory abnormality that might confound the results of the trial, interfere with the subject's participation for the full duration of the trial, or is not in the best interest of the subject to participate, in the opinion of the treating investigator
* Has known psychiatric or substance abuse disorders that would interfere with cooperation with the requirements of the trial
* Is pregnant or breastfeeding, or expecting to conceive or father children within the projected duration of the trial, starting with the pre-screening or screening visit through until at least 12 months after the last dose of study treatment
* Has received prior therapy with an anti-PD-1, anti-PD-L1, or anti-PD-L2 agent
* Has a known history of human immunodeficiency virus (HIV) (HIV 1/2 antibodies)
* Has known active hepatitis B (e.g., hepatitis B surface antigen \[HBsAg\] reactive) or hepatitis C (e.g., hepatitis C virus \[HCV\] ribonucleic acid \[RNA\] \[qualitative\] is detected)
* Has received a live vaccine within 30 days of planned start of study therapy. Administration of killed vaccines is allowed

  * Note: Seasonal influenza vaccines for injection are generally inactivated flu vaccines and are allowed; however intranasal influenza vaccines (e.g., Flu-Mist) are live attenuated vaccines, and are not allowed