Press the end of the stylus in to release it, then slide it out of the phone.

If your screen was locked, Moto Note will open so you can quickly jot a note without unlocking. . You can also change what happens when you remove the stylus. Learn more.
To keep track of your stylus:
When you remove the stylus from your unlocked phone, the stylus menu appears, giving you quick access to tools.

If you tap anywhere on the screen, the stylus menu shrinks to a bubble 

If you don’t want the menu when you remove the stylus, you can turn the menu off.
If you want the stylus menu but don't see it or 
In any app where you would type, you can handwrite with your stylus instead.
To handwrite:

In the text entry box, start writing with your stylus (or finger) and watch the text appear at the cursor.
If you don't see the handwriting keyboard, turn it on:

Swipe right, if needed, and turn on Handwriting layout.
If you don't see it, then Handwriting is not available for your language.
To learn more, read Google's help.