If:
Your app is installed on both A and B, and
You arrange for B to notify A that it needs to be locked, and
Your app on A is a properly-configured device administrator
Then your app on A can call lockNow()
on DevicePolicyManager
to lock the device.
The part that you ABSOLUTELY HAVE TO GET RIGHT is the communications from B to A. What you do not want to do is allow arbitrary other parties, such as the world's script kiddies, to go around locking people's devices on them. Using something (relatively) assured to be local, like Bluetooth, would help in this regard.