Hi The simple answer is that your first example contains an integrated (restrictive/defining) relative clause, whereas the second has a supplementary (non-defining/non-restrictive) relative clause. In integrated relatives you can leave out the relative word if it is the object of the relative clause, as seen in your first example, but you cannot omit the relative word in supplementary relative clauses, whatever its function. Incidentally, supplementary relatives are easy to spot because they are generally set apart by the use of commas (or dashes or brackets), as shown in your second example.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.