I'm assuming your question is about the scale change that occurs at the moment you parent one object to another with a net scale other than (1, 1, 1). This can be avoided, as described below. Any subsequent changes to the parent's scale will still cascade down to affect all children however, so if you want the object to retain its scale regardless of what happens to the parent, your options are either a script that applies a compensating scale to the child with each change, or changing your hierarchy so that the child is not parented to the scaling object (eg. using physics joints to connect their positions & rotations without scale leaking through)
You can use transform.SetParent(parent, false) to keep the object's local position, rotation, and scale unchanged when reparenting it:
public void SetParent(Transform parent, bool worldPositionStays);
Parameters
-------------------------------------------------------------------------------
parent The parent Transform to use.
worldPositionStays If true, the parent-relative position, scale and rotation
is modified such that the object keeps the same world space
position, rotation and scale as before.
Note that this may cause the object's resulting worldspace position & rotation to change as a consequence of the new parent's transform.
If you only want to keep the local scale, but allow the local position/rotation to be updated as normal, then you can do something like this:
var originalScale = myObj.transform.localScale;
myObj.transform.parent = newParent;
myObj.transform.localScale = originalScale;