Flip a flag from one row to another in a single query
Just flip it for both:

update the_table
   set is_active = not is_active
where device = 'd1'
  and id in (1,2);


For a more general approach see:  
How can I swap two values from particular column in a table in Postgres?