Here is an AppleScript that will automatically open up Displays Preference Pane and click Detect Displays on El Capitan (You’ll probably be prompted to give your app permission to use accessibility features):
tell application “System Events”
if not (UI elements enabled) then set UI elements enabled to true
tell application “System Preferences”
set current pane to pane “com.apple.preference.displays”
tell application “System Events” to tell process “System Preferences”
set frontmost to true
key down option
delay 0.1
click button “Detect Displays” of window 1
delay 1
tell application “System Events”
if (name of processes) contains “System Preferences” then tell application “System Preferences” to quit
end tell
end tell
end tell
end tell