In the sentence you provided, it is correct to keep the comma after "midterm." The phrase “which kept him wide awake for the all-nighter” is a non-restrictive relative clause providing additional information about the coffee.
However, you do not need to add a comma after "coffee," as it would separate the main clause from its modifying phrase unnecessarily.
So the sentence should read:
"To study for his calculus midterm, Brian drank seven cups of strong Turkish coffee which kept him wide awake for the all-nighter."
In summary, keep the comma after "midterm" and do not add a comma after "coffee."