The best way for the writer to create dramatic irony to increase tension in the story is:
by revealing the killer’s identity to readers right before the detective unknowingly enters a scene with the killer.
This approach allows the audience to be aware of the danger the detective is about to face while they are still unaware, thus heightening the tension as readers anticipate what will happen next.