Add object constraints and link to an object
Some tidy up.

In addition to @Leanders answer re limiting the constraint when using transform (which I've added in code below),  Note doesn't stop you setting  the z rotation property in UI to whatever..

If we wish to use context, would select those to add constraint to before script and then run from the context.  This is the fundamental concept of the context-operator paradigm. eg to run on object "A" select only "A" and run script below.

Test script. Adds constraint for all selected objects.  Note uses the reference to the newly created constraint con. It will have the default name only when there are no others with that name. Otherwise you add a new one and set the old one.  

I use context = bpy.context in test scripts, so they can be simply copied and pasted into operator or panel code later, where context is passed as an argument.

Added code to remove other constraints of same type first.

import bpy

context = bpy.context 

ob = context.object

for o in context.selected_objects:
    #o.constraints.clear() # removes all


    # remove other constraints by type
    lrcs = [c for c in o.constraints if c.type == 'LIMIT_ROTATION']
    while lrcs:
        o.constraints.remove(lrcs.pop())


    con = o.constraints.new( type='LIMIT_ROTATION')
    con.use_limit_z = True

    con.influence = 1
    con.min_z = 0.0872665
    con.max_z = 0.0872665

    con.owner_space = 'LOCAL'
    con.use_transform_limit = True


If you know the name of the target object is "A".  Unless you are going to later use operators on this object, there is no reason to set it as active and selected (context) to add modifiers to it this way.

scene = context.scene
o = scene.objects.get("A") #  if there is no object named A it will be None
if o:
    con = o.constraints.new(...) # as above.


For other constraints that need a target set, for example to add a constraint to each selected targeting context object

obs = context.selected_objects #safe to manipulate this prop
obs.remove(context.object)
for o in obs:
    con = o.constraint.new(...)
    con.object = context.object