Add Miracast function to newer Android versions
If Zillinium's suggestion to make changes into the "system / build.prop" does not make it fully function, you might need to also change the "/system/etc/wfdconfig.xml" file also. The following steps require both require root access and custom recovery TWRP.

Pre N (Nougat) the long way. You could use the nano command to add and/or change values, but for simplicity and to stay in-bounds, just use a file explorer and text editor. 


Go into the file /system/etc/wfdconfig.xml
Change the code:

...
&lt;ContentProtection&gt;
    &lt;Valid&gt;1&lt;/Valid&gt;
 ...


Change 1 to 0 to make it look like this code:

...
&lt;ContentProtection&gt;
    &lt;Valid&gt;0&lt;/Valid&gt;
...

Go into the file /system/build.prop. Go down to this line of code and AFTER it:

persist.debug.wfd.enable=1


Add a new line of code by creating this line:

persist.debug.wfd.appmonitoring=1

Save and exit.
Restart phone.
connect phone to computer.
Open an elevated command prompt and throw these commands:


adb shell
su
setprop persist.debug.wfd.appmonitoring 1

Verify the setprop getprop persist.debug.wfd.appmonitoring

If 1 is returned, then you should be good to go. 

Side note: if this should put you into a bootloop, go into custom recovery TWRP. 
Open a command prompt and throw these commands:


adb shell
chmod 644 /system/build.prop


That should fix bootloop.


For Android N (Nougat) the short way:

From the custom recovery TWRP:


Open a elevated command prompt:

adb reboot bootloader

Next, mount the /vendor partition from within TWRP`
Then throw the command:

adb shell 'echo persist.debug.wfd.enable=1 &gt;&gt;/vendor/build.prop'

Reboot system from TWRP menu


You should be good to go.